rewrote statusline to be compartmentalized into named components and easier to understand/customize as a basis

This commit is contained in:
zbirenbaum 2022-01-10 23:39:37 -05:00 committed by siduck
parent 8c2bbd2143
commit fa9f9aad0b
1 changed files with 357 additions and 314 deletions

View File

@ -62,7 +62,10 @@ table.insert(components.active, {})
table.insert(components.active, {}) table.insert(components.active, {})
table.insert(components.active, {}) table.insert(components.active, {})
components.active[1][1] = { local get_components = function()
local M = {}
M.main_icon = {
provider = statusline_style.main_icon, provider = statusline_style.main_icon,
hl = { hl = {
@ -76,7 +79,7 @@ components.active[1][1] = {
} }, } },
} }
components.active[1][2] = { M.file = {
provider = function() provider = function()
local filename = vim.fn.expand "%:t" local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e" local extension = vim.fn.expand "%:e"
@ -98,7 +101,7 @@ components.active[1][2] = {
right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } }, right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } },
} }
components.active[1][3] = { M.dir = {
provider = function() provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " " return "" .. dir_name .. " "
@ -121,7 +124,7 @@ components.active[1][3] = {
}, },
} }
components.active[1][4] = { M.git_added = {
provider = "git_diff_added", provider = "git_diff_added",
hl = { hl = {
fg = colors.grey_fg2, fg = colors.grey_fg2,
@ -129,8 +132,8 @@ components.active[1][4] = {
}, },
icon = "", icon = "",
} }
-- diffModfified
components.active[1][5] = { M.git_modified = {
provider = "git_diff_changed", provider = "git_diff_changed",
hl = { hl = {
fg = colors.grey_fg2, fg = colors.grey_fg2,
@ -138,8 +141,8 @@ components.active[1][5] = {
}, },
icon = "", icon = "",
} }
-- diffRemove
components.active[1][6] = { M.git_removed = {
provider = "git_diff_removed", provider = "git_diff_removed",
hl = { hl = {
fg = colors.grey_fg2, fg = colors.grey_fg2,
@ -148,7 +151,7 @@ components.active[1][6] = {
icon = "", icon = "",
} }
components.active[1][7] = { M.diagnostic_errors = {
provider = "diagnostic_errors", provider = "diagnostic_errors",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR) return lsp.diagnostics_exist(lsp_severity.ERROR)
@ -158,7 +161,7 @@ components.active[1][7] = {
icon = "", icon = "",
} }
components.active[1][8] = { M.diagnostic_warnings= {
provider = "diagnostic_warnings", provider = "diagnostic_warnings",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN) return lsp.diagnostics_exist(lsp_severity.WARN)
@ -167,7 +170,7 @@ components.active[1][8] = {
icon = "", icon = "",
} }
components.active[1][9] = { M.diagnostic_hints = {
provider = "diagnostic_hints", provider = "diagnostic_hints",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT) return lsp.diagnostics_exist(lsp_severity.HINT)
@ -176,7 +179,7 @@ components.active[1][9] = {
icon = "", icon = "",
} }
components.active[1][10] = { M.dianostic_info ={
provider = "diagnostic_info", provider = "diagnostic_info",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO) return lsp.diagnostics_exist(lsp_severity.INFO)
@ -185,7 +188,7 @@ components.active[1][10] = {
icon = "", icon = "",
} }
components.active[2][1] = { M.lsp_progress = {
provider = function() provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1] local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -223,7 +226,7 @@ components.active[2][1] = {
hl = { fg = colors.green }, hl = { fg = colors.green },
} }
components.active[3][1] = { M.lsp = {
provider = function() provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP" return " LSP"
@ -237,7 +240,7 @@ components.active[3][1] = {
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, hl = { fg = colors.grey_fg2, bg = colors.statusline_bg },
} }
components.active[3][2] = { M.git_branch = {
provider = "git_branch", provider = "git_branch",
enabled = shortline or function(winid) enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
@ -249,7 +252,7 @@ components.active[3][2] = {
icon = "", icon = "",
} }
components.active[3][3] = { M.git_right_separator = {
provider = " " .. statusline_style.left, provider = " " .. statusline_style.left,
hl = { hl = {
fg = colors.one_bg2, fg = colors.one_bg2,
@ -287,7 +290,7 @@ local chad_mode_hl = function()
} }
end end
components.active[3][4] = { M.mode_left_separator = {
provider = statusline_style.left, provider = statusline_style.left,
hl = function() hl = function()
return { return {
@ -297,7 +300,7 @@ components.active[3][4] = {
end, end,
} }
components.active[3][5] = { M.mode_icon = {
provider = statusline_style.vi_mode_icon, provider = statusline_style.vi_mode_icon,
hl = function() hl = function()
return { return {
@ -307,14 +310,14 @@ components.active[3][5] = {
end, end,
} }
components.active[3][6] = { M.mode_string = {
provider = function() provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " " return " " .. mode_colors[vim.fn.mode()][1] .. " "
end, end,
hl = chad_mode_hl, hl = chad_mode_hl,
} }
components.active[3][7] = { M.loc_spacer_left = {
provider = statusline_style.left, provider = statusline_style.left,
enabled = shortline or function(winid) enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -322,10 +325,10 @@ components.active[3][7] = {
hl = { hl = {
fg = colors.grey, fg = colors.grey,
bg = colors.one_bg, bg = colors.one_bg,
}, }
} }
components.active[3][8] = { M.loc_separator_left = {
provider = statusline_style.left, provider = statusline_style.left,
enabled = shortline or function(winid) enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -336,7 +339,7 @@ components.active[3][8] = {
}, },
} }
components.active[3][9] = { M.loc_position_icon = {
provider = statusline_style.position_icon, provider = statusline_style.position_icon,
enabled = shortline or function(winid) enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90 return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -344,10 +347,10 @@ components.active[3][9] = {
hl = { hl = {
fg = colors.black, fg = colors.black,
bg = colors.green, bg = colors.green,
}, }
} }
components.active[3][10] = { M.loc_position_text = {
provider = function() provider = function()
local current_line = vim.fn.line "." local current_line = vim.fn.line "."
local total_line = vim.fn.line "$" local total_line = vim.fn.line "$"
@ -370,6 +373,46 @@ components.active[3][10] = {
bg = colors.one_bg, bg = colors.one_bg,
}, },
} }
return M
end
local components_list = get_components()
local left = {}
local right = {}
local middle = {}
table.insert(left, components_list.main_icon)
table.insert(left, components_list.file)
table.insert(left, components_list.dir)
table.insert(left, components_list.git_added)
table.insert(left, components_list.git_modified)
table.insert(left, components_list.git_removed)
table.insert(left, components_list.diagnostic_errors)
table.insert(left, components_list.diagnostic_warnings)
table.insert(left, components_list.diagnostic_hints)
table.insert(left, components_list.diagnostic_info)
table.insert(middle, components_list.lsp_progress)
table.insert(right, components_list.lsp)
table.insert(right, components_list.git_branch)
table.insert(right, components_list.git_right_separator)
table.insert(right, components_list.mode_left_separator)
table.insert(right, components_list.mode_mode_icon)
table.insert(right, components_list.mode_mode_string)
table.insert(right, components_list.loc_spacer_left)
table.insert(right, components_list.loc_separator_left)
table.insert(right, components_list.loc_position_icon)
table.insert(right, components_list.loc_position_text)
components.active[1] = left
components.active[2] = middle
components.active[3] = right
require("feline").setup { require("feline").setup {
theme = { theme = {