ソースを参照

feat: move icons to a single icons file (#3115)

Philippe Richard 2 年 前
コミット
8767a17b5e

+ 1 - 0
lua/lvim/config/defaults.lua

@@ -13,6 +13,7 @@ return {
   keys = {},
 
   use_icons = true,
+  icons = require "lvim.icons",
 
   builtin = {},
 

+ 10 - 6
lua/lvim/core/alpha/dashboard.lua

@@ -113,12 +113,16 @@ function M.get_sections()
     end
     buttons = {
       val = {
-        button("f", "  Find File", "<CMD>Telescope find_files<CR>"),
-        button("n", "  New File", "<CMD>ene!<CR>"),
-        button("p", "  Projects ", "<CMD>Telescope projects<CR>"),
-        button("r", "  Recent files", ":Telescope oldfiles <CR>"),
-        button("t", "  Find Text", "<CMD>Telescope live_grep<CR>"),
-        button("c", "  Configuration", "<CMD>edit " .. require("lvim.config"):get_user_config_path() .. " <CR>"),
+        button("f", lvim.icons.ui.FindFile .. "  Find File", "<CMD>Telescope find_files<CR>"),
+        button("n", lvim.icons.ui.NewFile .. "  New File", "<CMD>ene!<CR>"),
+        button("p", lvim.icons.ui.Project .. "  Projects ", "<CMD>Telescope projects<CR>"),
+        button("r", lvim.icons.ui.History .. "  Recent files", ":Telescope oldfiles <CR>"),
+        button("t", lvim.icons.ui.FindText .. "  Find Text", "<CMD>Telescope live_grep<CR>"),
+        button(
+          "c",
+          lvim.icons.ui.Gear .. "  Configuration",
+          "<CMD>edit " .. require("lvim.config"):get_user_config_path() .. " <CR>"
+        ),
       },
     }
   end

+ 1 - 1
lua/lvim/core/alpha/startify.lua

@@ -19,7 +19,7 @@ function M.get_sections()
 
   local top_buttons = {
     entries = {
-      { "e", "  New File", "<CMD>ene!<CR>" },
+      { "e", lvim.icons.ui.NewFile .. " New File", "<CMD>ene!<CR>" },
     },
     val = {},
   }

+ 3 - 38
lua/lvim/core/breadcrumbs.lua

@@ -7,42 +7,7 @@ M.config = function()
     active = false,
     on_config_done = nil,
     options = {
-      icons = {
-        Text = " ",
-        Method = " ",
-        Function = " ",
-        Constructor = " ",
-        Field = " ",
-        Variable = " ",
-        Class = " ",
-        Interface = " ",
-        Module = " ",
-        Property = " ",
-        Unit = " ",
-        Value = " ",
-        Enum = " ",
-        Keyword = " ",
-        Snippet = " ",
-        Color = " ",
-        File = " ",
-        Reference = " ",
-        Folder = " ",
-        EnumMember = " ",
-        Constant = " ",
-        Struct = " ",
-        Event = " ",
-        Operator = " ",
-        TypeParameter = " ",
-        Array = " ",
-        Number = " ",
-        String = " ",
-        Boolean = "蘒",
-        Object = " ",
-        Package = " ",
-        Namespace = "",
-        Key = "",
-        Null = "ﳠ",
-      },
+      icons = lvim.icons.kind,
       highlight = true,
       separator = " " .. ">" .. " ",
       depth_limit = 0,
@@ -107,7 +72,7 @@ M.get_filename = function()
 
     vim.api.nvim_set_hl(0, hl_group, { fg = file_icon_color })
     if f.isempty(file_icon) then
-      file_icon = ""
+      file_icon = lvim.icons.kind.File
     end
 
     local navic_text = vim.api.nvim_get_hl_by_name("Normal", true)
@@ -165,7 +130,7 @@ M.get_winbar = function()
 
   if not f.isempty(value) and f.get_buf_option "mod" then
     -- TODO: replace with circle
-    local mod = "%#LspCodeLens#" .. "" .. "%*"
+    local mod = "%#LspCodeLens#" .. lvim.icons.ui.Circle .. "%*"
     if gps_added then
       value = value .. " " .. mod
     else

+ 11 - 7
lua/lvim/core/bufferline.lua

@@ -6,7 +6,11 @@ end
 
 local function diagnostics_indicator(num, _, diagnostics, _)
   local result = {}
-  local symbols = { error = "", warning = "", info = "" }
+  local symbols = {
+    error = lvim.icons.diagnostics.Error,
+    warning = lvim.icons.diagnostics.Warning,
+    info = lvim.icons.diagnostics.Information,
+  }
   if not lvim.use_icons then
     return "(" .. num .. ")"
   end
@@ -59,14 +63,14 @@ M.config = function()
       left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions"
       middle_mouse_command = nil, -- can be a string | function, see "Mouse actions"
       indicator = {
-        icon = "▎", -- this should be omitted if indicator style is not 'icon'
+        icon = lvim.icons.ui.BoldLineLeft, -- this should be omitted if indicator style is not 'icon'
         style = "icon", -- can also be 'underline'|'none',
       },
-      buffer_close_icon = "",
-      modified_icon = "●",
-      close_icon = "",
-      left_trunc_marker = "",
-      right_trunc_marker = "",
+      buffer_close_icon = lvim.icons.ui.Close,
+      modified_icon = lvim.icons.ui.Circle,
+      close_icon = lvim.icons.ui.BoldClose,
+      left_trunc_marker = lvim.icons.ui.ArrowCircleLeft,
+      right_trunc_marker = lvim.icons.ui.ArrowCircleRight,
       --- name_formatter can be used to change the buffer's label in the bufferline.
       --- Please note some names can/will break the
       --- bufferline so use this at your discretion knowing that it has

+ 2 - 28
lua/lvim/core/cmp.lua

@@ -141,33 +141,7 @@ M.config = function()
     formatting = {
       fields = { "kind", "abbr", "menu" },
       max_width = 0,
-      kind_icons = {
-        Class = " ",
-        Color = " ",
-        Constant = "ﲀ ",
-        Constructor = " ",
-        Enum = "練",
-        EnumMember = " ",
-        Event = " ",
-        Field = " ",
-        File = "",
-        Folder = " ",
-        Function = " ",
-        Interface = "ﰮ ",
-        Keyword = " ",
-        Method = " ",
-        Module = " ",
-        Operator = "",
-        Property = " ",
-        Reference = " ",
-        Snippet = " ",
-        Struct = " ",
-        Text = " ",
-        TypeParameter = " ",
-        Unit = "塞",
-        Value = " ",
-        Variable = " ",
-      },
+      kind_icons = lvim.icons.kind,
       source_names = {
         nvim_lsp = "(LSP)",
         emoji = "(Emoji)",
@@ -189,7 +163,7 @@ M.config = function()
       format = function(entry, vim_item)
         local max_width = lvim.builtin.cmp.formatting.max_width
         if max_width ~= 0 and #vim_item.abbr > max_width then
-          vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. "…"
+          vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. lvim.icons.ui.Ellipsis
         end
         if lvim.use_icons then
           vim_item.kind = lvim.builtin.cmp.formatting.kind_icons[vim_item.kind]

+ 3 - 3
lua/lvim/core/dap.lua

@@ -5,19 +5,19 @@ M.config = function()
     active = false,
     on_config_done = nil,
     breakpoint = {
-      text = "",
+      text = lvim.icons.ui.Bug,
       texthl = "LspDiagnosticsSignError",
       linehl = "",
       numhl = "",
     },
     breakpoint_rejected = {
-      text = "",
+      text = lvim.icons.ui.Bug,
       texthl = "LspDiagnosticsSignHint",
       linehl = "",
       numhl = "",
     },
     stopped = {
-      text = "",
+      text = lvim.icons.ui.BoldArrowRight,
       texthl = "LspDiagnosticsSignInformation",
       linehl = "DiagnosticUnderlineInfo",
       numhl = "LspDiagnosticsSignInformation",

+ 5 - 5
lua/lvim/core/gitsigns.lua

@@ -8,31 +8,31 @@ M.config = function()
       signs = {
         add = {
           hl = "GitSignsAdd",
-          text = "▎",
+          text = lvim.icons.ui.BoldLineLeft,
           numhl = "GitSignsAddNr",
           linehl = "GitSignsAddLn",
         },
         change = {
           hl = "GitSignsChange",
-          text = "▎",
+          text = lvim.icons.ui.BoldLineLeft,
           numhl = "GitSignsChangeNr",
           linehl = "GitSignsChangeLn",
         },
         delete = {
           hl = "GitSignsDelete",
-          text = "契",
+          text = lvim.icons.ui.Triangle,
           numhl = "GitSignsDeleteNr",
           linehl = "GitSignsDeleteLn",
         },
         topdelete = {
           hl = "GitSignsDelete",
-          text = "契",
+          text = lvim.icons.ui.Triangle,
           numhl = "GitSignsDeleteNr",
           linehl = "GitSignsDeleteLn",
         },
         changedelete = {
           hl = "GitSignsChange",
-          text = "▎",
+          text = lvim.icons.ui.BoldLineLeft,
           numhl = "GitSignsChangeNr",
           linehl = "GitSignsChangeLn",
         },

+ 1 - 1
lua/lvim/core/indentlines.lua

@@ -17,7 +17,7 @@ M.config = function()
         "Trouble",
         "text",
       },
-      char = "▏",
+      char = lvim.icons.ui.LineLeft,
       show_trailing_blankline_indent = false,
       show_first_indent_level = true,
       use_treesitter = true,

+ 7 - 7
lua/lvim/core/info.lua

@@ -25,8 +25,8 @@ local function make_formatters_info(ft)
     "Formatters info",
     fmt(
       "* Active: %s%s",
-      table.concat(registered_formatters, "  , "),
-      vim.tbl_count(registered_formatters) > 0 and "  " or ""
+      table.concat(registered_formatters, " " .. lvim.icons.ui.BoxChecked .. " , "),
+      vim.tbl_count(registered_formatters) > 0 and " " .. lvim.icons.ui.BoxChecked .. " " or ""
     ),
     fmt("* Supported: %s", str_list(supported_formatters)),
   }
@@ -41,8 +41,8 @@ local function make_code_actions_info(ft)
     "Code actions info",
     fmt(
       "* Active: %s%s",
-      table.concat(registered_actions, "  , "),
-      vim.tbl_count(registered_actions) > 0 and "  " or ""
+      table.concat(registered_actions, " " .. lvim.icons.ui.BoxChecked .. " , "),
+      vim.tbl_count(registered_actions) > 0 and " " .. lvim.icons.ui.BoxChecked .. " " or ""
     ),
   }
 
@@ -57,8 +57,8 @@ local function make_linters_info(ft)
     "Linters info",
     fmt(
       "* Active: %s%s",
-      table.concat(registered_linters, "  , "),
-      vim.tbl_count(registered_linters) > 0 and "  " or ""
+      table.concat(registered_linters, " " .. lvim.icons.ui.BoxChecked .. " , "),
+      vim.tbl_count(registered_linters) > 0 and " " .. lvim.icons.ui.BoxChecked .. " " or ""
     ),
     fmt("* Supported: %s", str_list(supported_linters)),
   }
@@ -202,7 +202,7 @@ function M.toggle_popup(ft)
     vim.fn.matchadd("LvimInfoIdentifier", " " .. ft .. "$")
     vim.fn.matchadd("string", "true")
     vim.fn.matchadd("string", "active")
-    vim.fn.matchadd("string", "")
+    vim.fn.matchadd("string", lvim.icons.ui.BoxChecked)
     vim.fn.matchadd("boolean", "inactive")
     vim.fn.matchadd("error", "false")
     tbl_set_highlight(require("lvim.lsp.null-ls.formatters").list_registered(ft), "LvimInfoIdentifier")

+ 1 - 1
lua/lvim/core/lir.lua

@@ -85,7 +85,7 @@ M.config = function()
   -- custom folder icon
   reload("nvim-web-devicons").set_icon {
     lir_folder_icon = {
-      icon = "",
+      icon = lvim.icons.ui.Folder,
       color = "#42A5F5",
       name = "LirFolderNode",
     },

+ 21 - 10
lua/lvim/core/lualine/components.lua

@@ -21,25 +21,25 @@ vim.api.nvim_set_hl(0, "SLBranchName", { fg = normal_hl.foreground, bg = cursorl
 vim.api.nvim_set_hl(0, "SLProgress", { fg = "#ECBE7B", bg = statusline_hl.background })
 
 local location_color = nil
-local branch = ""
-local separator = "│"
+local branch = lvim.icons.git.Branch
+local separator = lvim.icons.ui.LineMiddle
 
 if lvim.colorscheme == "tokyonight" then
   location_color = "SLBranchName"
-  branch = "%#SLGitIcon#" .. "" .. "%*" .. "%#SLBranchName#"
+  branch = "%#SLGitIcon#" .. lvim.icons.git.Branch .. "%*" .. "%#SLBranchName#"
 
   local status_ok, tnc = pcall(require, "tokyonight.colors")
   if status_ok then
     local tncolors = tnc.setup { transform = true }
     vim.api.nvim_set_hl(0, "SLSeparator", { fg = cursorline_hl.background, bg = tncolors.black })
-    separator = "%#SLSeparator#" .. "│" .. "%*"
+    separator = "%#SLSeparator#" .. lvim.icons.ui.LineMiddle .. "%*"
   end
 end
 
 return {
   mode = {
     function()
-      return "  "
+      return " " .. lvim.icons.ui.Target .. " "
     end,
     padding = { left = 0, right = 0 },
     color = {},
@@ -58,7 +58,11 @@ return {
   diff = {
     "diff",
     source = diff_source,
-    symbols = { added = " ", modified = " ", removed = " " },
+    symbols = {
+      added = lvim.icons.git.LineAdded .. " ",
+      modified = lvim.icons.git.LineModified .. " ",
+      removed = lvim.icons.git.LineRemoved .. " ",
+    },
     padding = { left = 2, right = 1 },
     diff_color = {
       added = { fg = colors.green },
@@ -73,7 +77,9 @@ return {
       if vim.bo.filetype == "python" then
         local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
         if venv then
-          return string.format("  (%s)", utils.env_cleanup(venv))
+          local icons = require "nvim-web-devicons"
+          local py_icon, _ = icons.get_icon ".py"
+          return string.format(" " .. py_icon .. " (%s)", utils.env_cleanup(venv))
         end
       end
       return ""
@@ -84,12 +90,17 @@ return {
   diagnostics = {
     "diagnostics",
     sources = { "nvim_diagnostic" },
-    symbols = { error = " ", warn = " ", info = " ", hint = " " },
+    symbols = {
+      error = lvim.icons.diagnostics.BoldError .. " ",
+      warn = lvim.icons.diagnostics.BoldWarning .. " ",
+      info = lvim.icons.diagnostics.BoldInformation .. " ",
+      hint = lvim.icons.diagnostics.BoldHint .. " ",
+    },
     -- cond = conditions.hide_in_width,
   },
   treesitter = {
     function()
-      return ""
+      return lvim.icons.ui.Tree
     end,
     color = function()
       local buf = vim.api.nvim_get_current_buf()
@@ -148,7 +159,7 @@ return {
   spaces = {
     function()
       local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
-      return " " .. shiftwidth
+      return lvim.icons.ui.Tab .. " " .. shiftwidth
     end,
     separator = separator,
     padding = 1,

+ 8 - 2
lua/lvim/core/lualine/styles.lua

@@ -43,8 +43,14 @@ styles.default = {
     theme = "auto",
     globalstatus = true,
     icons_enabled = lvim.use_icons,
-    component_separators = { left = "", right = "" },
-    section_separators = { left = "", right = "" },
+    component_separators = {
+      left = lvim.icons.ui.DividerRight,
+      right = lvim.icons.ui.DividerLeft,
+    },
+    section_separators = {
+      left = lvim.icons.ui.BoldDividerRight,
+      right = lvim.icons.ui.BoldDividerLeft,
+    },
     disabled_filetypes = {},
   },
   sections = {

+ 5 - 5
lua/lvim/core/notify.lua

@@ -29,11 +29,11 @@ local defaults = {
 
     ---@usage Icons for the different levels
     icons = {
-      ERROR = "",
-      WARN = "",
-      INFO = "",
-      DEBUG = "",
-      TRACE = "✎",
+      ERROR = lvim.icons.diagnostics.Error,
+      WARN = lvim.icons.diagnostics.Warning,
+      INFO = lvim.icons.diagnostics.Information,
+      DEBUG = lvim.icons.diagnostics.Debug,
+      TRACE = lvim.icons.diagnostics.Trace,
     },
   },
 }

+ 18 - 18
lua/lvim/core/nvimtree.lua

@@ -20,10 +20,10 @@ function M.config()
         enable = lvim.use_icons,
         show_on_dirs = false,
         icons = {
-          hint = "",
-          info = "",
-          warning = "",
-          error = "",
+          hint = lvim.icons.diagnostics.BoldHint,
+          info = lvim.icons.diagnostics.BoldInformation,
+          warning = lvim.icons.diagnostics.BoldWarning,
+          error = lvim.icons.diagnostics.BoldError,
         },
       },
       update_focused_file = {
@@ -71,23 +71,23 @@ function M.config()
             folder_arrow = lvim.use_icons,
           },
           glyphs = {
-            default = "",
-            symlink = "",
+            default = lvim.icons.ui.Text,
+            symlink = lvim.icons.ui.FileSymlink,
             git = {
-              unstaged = "",
-              staged = "S",
-              unmerged = "",
-              renamed = "➜",
-              deleted = "",
-              untracked = "U",
-              ignored = "◌",
+              deleted = lvim.icons.git.FileDeleted,
+              ignored = lvim.icons.git.FileIgnored,
+              renamed = lvim.icons.git.FileRenamed,
+              staged = lvim.icons.git.FileStaged,
+              unmerged = lvim.icons.git.FileUnmerged,
+              unstaged = lvim.icons.git.FileUnstaged,
+              untracked = lvim.icons.git.FileUntracked,
             },
             folder = {
-              default = "",
-              open = "",
-              empty = "",
-              empty_open = "",
-              symlink = "",
+              default = lvim.icons.ui.Folder,
+              empty = lvim.icons.ui.EmptyFolder,
+              empty_open = lvim.icons.ui.EmptyFolderOpen,
+              open = lvim.icons.ui.FolderOpen,
+              symlink = lvim.icons.ui.FolderSymlink,
             },
           },
         },

+ 2 - 2
lua/lvim/core/telescope.lua

@@ -63,8 +63,8 @@ function M.config()
   end
   lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
     defaults = {
-      prompt_prefix = " ",
-      selection_caret = " ",
+      prompt_prefix = lvim.icons.ui.Telescope .. " ",
+      selection_caret = lvim.icons.ui.Forward .. " ",
       entry_prefix = "  ",
       initial_mode = "insert",
       selection_strategy = "reset",

+ 3 - 3
lua/lvim/core/which-key.lua

@@ -22,9 +22,9 @@ M.config = function()
         spelling = { enabled = true, suggestions = 20 }, -- use which-key for spelling hints
       },
       icons = {
-        breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
-        separator = "➜", -- symbol used between a key and it's label
-        group = "+", -- symbol prepended to a group
+        breadcrumb = lvim.icons.ui.DoubleChevronRight, -- symbol used in the command line area that shows your active key combo
+        separator = lvim.icons.ui.BoldArrowRight, -- symbol used between a key and it's label
+        group = lvim.icons.ui.Plus, -- symbol prepended to a group
       },
       popup_mappings = {
         scroll_down = "<c-d>", -- binding to scroll down inside the popup

+ 141 - 0
lua/lvim/icons.lua

@@ -0,0 +1,141 @@
+return {
+  kind = {
+    Array = "",
+    Boolean = "蘒",
+    Class = "",
+    Color = "",
+    Constant = "",
+    Constructor = "",
+    Enum = "",
+    EnumMember = "",
+    Event = "",
+    Field = "",
+    File = "",
+    Folder = "",
+    Function = "",
+    Interface = "",
+    Key = "",
+    Keyword = "",
+    Method = "",
+    Module = "",
+    Namespace = "",
+    Null = "ﳠ",
+    Number = "",
+    Object = "",
+    Operator = "",
+    Package = "",
+    Property = "",
+    Reference = "",
+    Snippet = "",
+    String = "",
+    Struct = "",
+    Text = "",
+    TypeParameter = "",
+    Unit = "",
+    Value = "",
+    Variable = "",
+  },
+  git = {
+    LineAdded = "",
+    LineModified = "",
+    LineRemoved = "",
+    FileDeleted = "",
+    FileIgnored = "◌",
+    FileRenamed = "➜",
+    FileStaged = "S",
+    FileUnmerged = "",
+    FileUnstaged = "",
+    FileUntracked = "U",
+    Diff = "",
+    Repo = "",
+    Octoface = "",
+    Branch = "",
+  },
+  ui = {
+    ArrowCircleDown = "",
+    ArrowCircleLeft = "",
+    ArrowCircleRight = "",
+    ArrowCircleUp = "",
+    BoldArrowDown = "",
+    BoldArrowLeft = "",
+    BoldArrowRight = "",
+    BoldArrowUp = "",
+    BoldClose = "",
+    BoldDividerLeft = "",
+    BoldDividerRight = "",
+    BoldLineLeft = "▎",
+    BookMark = "",
+    BoxChecked = "",
+    Bug = "",
+    Calendar = "",
+    Check = "",
+    ChevronRight = ">",
+    ChevronShortDown = "",
+    ChevronShortLeft = "",
+    ChevronShortRight = "",
+    ChevronShortUp = "",
+    Circle = "",
+    Close = "",
+    CloudDownload = "",
+    Code = "",
+    Comment = "",
+    Dashboard = "",
+    DividerLeft = "",
+    DividerRight = "",
+    DoubleChevronRight = "»",
+    Ellipsis = "…",
+    EmptyFolder = "",
+    EmptyFolderOpen = "",
+    File = "",
+    FileSymlink = "",
+    Files = "",
+    FindFile = "",
+    FindText = "",
+    Fire = "",
+    Folder = "",
+    FolderOpen = "",
+    FolderSymlink = "",
+    Forward = "",
+    Gear = "",
+    History = "",
+    Lightbulb = "",
+    LineLeft = "▏",
+    LineMiddle = "│",
+    List = "",
+    Lock = "",
+    NewFile = "",
+    Note = "",
+    Package = "",
+    Pencil = "",
+    Plus = "",
+    Project = "",
+    Search = "",
+    SignIn = "",
+    SignOut = "",
+    Tab = "",
+    Table = "",
+    Target = "",
+    Telescope = "",
+    Text = "",
+    Tree = "",
+    Triangle = "契",
+    TriangleShortArrowDown = "",
+    TriangleShortArrowLeft = "",
+    TriangleShortArrowRight = "",
+    TriangleShortArrowUp = "",
+  },
+  diagnostics = {
+    BoldError = "",
+    Error = "",
+    BoldWarning = "",
+    Warning = "",
+    BoldInformation = "",
+    Information = "",
+    BoldQuestion = "",
+    Question = "",
+    BoldHint = "",
+    Hint = "",
+    Debug = "",
+    Trace = "✎",
+  },
+}

+ 4 - 4
lua/lvim/lsp/config.lua

@@ -47,10 +47,10 @@ return {
     signs = {
       active = true,
       values = {
-        { name = "DiagnosticSignError", text = "" },
-        { name = "DiagnosticSignWarn", text = "" },
-        { name = "DiagnosticSignHint", text = "" },
-        { name = "DiagnosticSignInfo", text = "" },
+        { name = "DiagnosticSignError", text = lvim.icons.diagnostics.Error },
+        { name = "DiagnosticSignWarn", text = lvim.icons.diagnostics.Warning },
+        { name = "DiagnosticSignHint", text = lvim.icons.diagnostics.Hint },
+        { name = "DiagnosticSignInfo", text = lvim.icons.diagnostics.Info },
       },
     },
     virtual_text = true,