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

View File

@ -62,7 +62,10 @@ 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,
hl = {
@ -74,9 +77,9 @@ components.active[1][1] = {
fg = colors.nord_blue,
bg = colors.lightbg,
} },
}
}
components.active[1][2] = {
M.file = {
provider = function()
local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e"
@ -96,9 +99,9 @@ components.active[1][2] = {
},
right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } },
}
}
components.active[1][3] = {
M.dir = {
provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " "
@ -119,36 +122,36 @@ components.active[1][3] = {
bg = colors.statusline_bg,
},
},
}
}
components.active[1][4] = {
M.git_added = {
provider = "git_diff_added",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
-- diffModfified
components.active[1][5] = {
}
M.git_modified = {
provider = "git_diff_changed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
-- diffRemove
components.active[1][6] = {
}
M.git_removed = {
provider = "git_diff_removed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
}
components.active[1][7] = {
M.diagnostic_errors = {
provider = "diagnostic_errors",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR)
@ -156,36 +159,36 @@ components.active[1][7] = {
hl = { fg = colors.red },
icon = "",
}
}
components.active[1][8] = {
M.diagnostic_warnings= {
provider = "diagnostic_warnings",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN)
end,
hl = { fg = colors.yellow },
icon = "",
}
}
components.active[1][9] = {
M.diagnostic_hints = {
provider = "diagnostic_hints",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT)
end,
hl = { fg = colors.grey_fg2 },
icon = "",
}
}
components.active[1][10] = {
M.dianostic_info ={
provider = "diagnostic_info",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO)
end,
hl = { fg = colors.green },
icon = "",
}
}
components.active[2][1] = {
M.lsp_progress = {
provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -221,9 +224,9 @@ components.active[2][1] = {
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = { fg = colors.green },
}
}
components.active[3][1] = {
M.lsp = {
provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP"
@ -235,9 +238,9 @@ components.active[3][1] = {
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg },
}
}
components.active[3][2] = {
M.git_branch = {
provider = "git_branch",
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
@ -247,17 +250,17 @@ components.active[3][2] = {
bg = colors.statusline_bg,
},
icon = "",
}
}
components.active[3][3] = {
M.git_right_separator = {
provider = " " .. statusline_style.left,
hl = {
fg = colors.one_bg2,
bg = colors.statusline_bg,
},
}
}
local mode_colors = {
local mode_colors = {
["n"] = { "NORMAL", colors.red },
["no"] = { "N-PENDING", colors.red },
["i"] = { "INSERT", colors.dark_purple },
@ -278,16 +281,16 @@ local mode_colors = {
["rm"] = { "MORE", colors.teal },
["r?"] = { "CONFIRM", colors.teal },
["!"] = { "SHELL", colors.green },
}
}
local chad_mode_hl = function()
local chad_mode_hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg,
}
end
end
components.active[3][4] = {
M.mode_left_separator = {
provider = statusline_style.left,
hl = function()
return {
@ -295,9 +298,9 @@ components.active[3][4] = {
bg = colors.one_bg2,
}
end,
}
}
components.active[3][5] = {
M.mode_icon = {
provider = statusline_style.vi_mode_icon,
hl = function()
return {
@ -305,16 +308,16 @@ components.active[3][5] = {
bg = mode_colors[vim.fn.mode()][2],
}
end,
}
}
components.active[3][6] = {
M.mode_string = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
end,
hl = chad_mode_hl,
}
}
components.active[3][7] = {
M.loc_spacer_left = {
provider = statusline_style.left,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -322,10 +325,10 @@ components.active[3][7] = {
hl = {
fg = colors.grey,
bg = colors.one_bg,
},
}
}
}
components.active[3][8] = {
M.loc_separator_left = {
provider = statusline_style.left,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -334,9 +337,9 @@ components.active[3][8] = {
fg = colors.green,
bg = colors.grey,
},
}
}
components.active[3][9] = {
M.loc_position_icon = {
provider = statusline_style.position_icon,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -344,10 +347,10 @@ components.active[3][9] = {
hl = {
fg = colors.black,
bg = colors.green,
},
}
}
}
components.active[3][10] = {
M.loc_position_text = {
provider = function()
local current_line = vim.fn.line "."
local total_line = vim.fn.line "$"
@ -369,7 +372,47 @@ components.active[3][10] = {
fg = colors.green,
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 {
theme = {