浏览代码

[Feature] enhance lualine config (#1372)

chaeing 3 年之前
父节点
当前提交
378c1c3eb5
共有 4 个文件被更改,包括 40 次插入51 次删除
  1. 27 9
      lua/core/lualine/components.lua
  2. 1 1
      lua/core/lualine/init.lua
  3. 9 41
      lua/core/lualine/styles.lua
  4. 3 0
      lua/core/lualine/utils.lua

+ 27 - 9
lua/core/lualine/components.lua

@@ -2,13 +2,16 @@ local conditions = require "core.lualine.conditions"
 local colors = require "core.lualine.colors"
 
 return {
-  vi_mode = {
+  mode = {
     function()
       return " "
     end,
     left_padding = 0,
     right_padding = 0,
-    condition = conditions.hide_in_width,
+    condition = function()
+      return true
+    end,
+    color = {},
   },
   branch = {
     "branch",
@@ -16,6 +19,14 @@ return {
     condition = function()
       return conditions.hide_in_width() and conditions.check_git_workspace()
     end,
+    color = { gui = "bold" },
+  },
+  filename = {
+    "filename",
+    condition = function()
+      return true
+    end,
+    color = {},
   },
   diff = {
     "diff",
@@ -24,6 +35,7 @@ return {
     color_modified = { fg = colors.yellow },
     color_removed = { fg = colors.red },
     condition = conditions.hide_in_width,
+    color = {},
   },
   python_env = {
     function()
@@ -41,14 +53,15 @@ return {
       end
       return ""
     end,
-    color = { fg = colors.green },
     condition = conditions.hide_in_width,
+    color = { fg = colors.green },
   },
   diagnostics = {
     "diagnostics",
     sources = { "nvim_lsp" },
     symbols = { error = " ", warn = " ", info = " ", hint = " " },
     condition = conditions.hide_in_width,
+    color = {},
   },
   treesitter = {
     function()
@@ -57,8 +70,8 @@ return {
       end
       return ""
     end,
-    color = { fg = colors.green },
     condition = conditions.hide_in_width,
+    color = { fg = colors.green },
   },
   lsp = {
     function(msg)
@@ -92,12 +105,12 @@ return {
 
       return table.concat(buf_client_names, ", ")
     end,
-    condition = conditions.hide_in_width,
     icon = " ",
+    condition = conditions.hide_in_width,
     color = { gui = "bold" },
   },
-  location = { "location", condition = conditions.hide_in_width },
-  progress = { "progress", condition = conditions.hide_in_width },
+  location = { "location", condition = conditions.hide_in_width, color = {} },
+  progress = { "progress", condition = conditions.hide_in_width, color = {} },
   spaces = {
     function()
       local label = "Spaces: "
@@ -107,13 +120,15 @@ return {
       return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " "
     end,
     condition = conditions.hide_in_width,
+    color = {},
   },
   encoding = {
     "o:encoding",
     upper = true,
     condition = conditions.hide_in_width,
+    color = {},
   },
-  filetype = { "filetype", condition = conditions.hide_in_width },
+  filetype = { "filetype", condition = conditions.hide_in_width, color = {} },
   scrollbar = {
     function()
       local current_line = vim.fn.line "."
@@ -123,8 +138,11 @@ return {
       local index = math.ceil(line_ratio * #chars)
       return chars[index]
     end,
-    color = { fg = colors.yellow, bg = colors.bg },
     left_padding = 0,
     right_padding = 0,
+    condition = function()
+      return true
+    end,
+    color = { fg = colors.yellow, bg = colors.bg },
   },
 }

+ 1 - 1
lua/core/lualine/init.lua

@@ -40,7 +40,7 @@ M.setup = function()
   lualine.setup(lvim.builtin.lualine)
 
   if lvim.builtin.lualine.on_config_done then
-    lvim.builtin.lualine.on_config_done(lualine, lvim.builtin.lualine)
+    lvim.builtin.lualine.on_config_done(lualine)
   end
 end
 

+ 9 - 41
lua/core/lualine/styles.lua

@@ -69,14 +69,15 @@ styles.lvim = {
     icons_enabled = true,
     component_separators = "",
     section_separators = "",
-    disabled_filetypes = { "dashboard", "" },
+    disabled_filetypes = { "dashboard" },
   },
   sections = {
     lualine_a = {
-      components.vi_mode,
+      components.mode,
     },
     lualine_b = {
       components.branch,
+      components.filename,
     },
     lualine_c = {
       components.diff,
@@ -86,15 +87,9 @@ styles.lvim = {
       components.diagnostics,
       components.treesitter,
       components.lsp,
-      -- components.location,
-      -- components.progress,
-      -- components.spaces,
-      -- components.encoding,
       components.filetype,
     },
-    lualine_y = {
-      -- components.filetype,
-    },
+    lualine_y = {},
     lualine_z = {
       components.scrollbar,
     },
@@ -132,39 +127,12 @@ function M.get_style(style)
 end
 
 function M.update()
-  local config = lvim.builtin.lualine
-  local style = M.get_style(config.style)
+  local style = M.get_style(lvim.builtin.lualine.style)
+  if lvim.builtin.lualine.options.theme == nil then
+    lvim.builtin.lualine.options.theme = lvim.colorscheme
+  end
 
-  lvim.builtin.lualine = {
-    active = true,
-    style = style.style,
-    options = {
-      icons_enabled = config.options.icons_enabled or style.options.icons_enabled,
-      component_separators = config.options.component_separators or style.options.component_separators,
-      section_separators = config.options.section_separators or style.options.section_separators,
-      theme = config.options.theme or lvim.colorscheme or "auto",
-      disabled_filetypes = config.options.disabled_filetypes or style.options.disabled_filetypes,
-    },
-    sections = {
-      lualine_a = config.sections.lualine_a or style.sections.lualine_a,
-      lualine_b = config.sections.lualine_b or style.sections.lualine_b,
-      lualine_c = config.sections.lualine_c or style.sections.lualine_c,
-      lualine_x = config.sections.lualine_x or style.sections.lualine_x,
-      lualine_y = config.sections.lualine_y or style.sections.lualine_y,
-      lualine_z = config.sections.lualine_z or style.sections.lualine_z,
-    },
-    inactive_sections = {
-      lualine_a = config.inactive_sections.lualine_a or style.inactive_sections.lualine_a,
-      lualine_b = config.inactive_sections.lualine_b or style.inactive_sections.lualine_b,
-      lualine_c = config.inactive_sections.lualine_c or style.inactive_sections.lualine_c,
-      lualine_x = config.inactive_sections.lualine_x or style.inactive_sections.lualine_x,
-      lualine_y = config.inactive_sections.lualine_y or style.inactive_sections.lualine_y,
-      lualine_z = config.inactive_sections.lualine_z or style.inactive_sections.lualine_z,
-    },
-    tabline = config.tabline or style.tabline,
-    extensions = config.extensions or style.extensions,
-    on_config_done = config.on_config_done,
-  }
+  lvim.builtin.lualine = vim.tbl_deep_extend("keep", lvim.builtin.lualine, style)
 end
 
 return M

+ 3 - 0
lua/core/lualine/utils.lua

@@ -2,6 +2,9 @@ local M = {}
 
 function M.validate_theme()
   local theme = lvim.builtin.lualine.options.theme
+  if type(theme) == "table" then
+    return
+  end
 
   local lualine_loader = require "lualine.utils.loader"
   local ok = pcall(lualine_loader.load_theme, theme)