clean | organize statusline config

This commit is contained in:
siduck 2022-01-11 11:42:02 +05:30
parent fa9f9aad0b
commit a21ee2f22f

View File

@ -55,17 +55,9 @@ local shortline = config.shortline == false and true
-- Initialize the components table -- Initialize the components table
local components = { local components = {
active = {}, active = {},
inactive = {},
} }
table.insert(components.active, {}) local main_icon = {
table.insert(components.active, {})
table.insert(components.active, {})
local get_components = function()
local M = {}
M.main_icon = {
provider = statusline_style.main_icon, provider = statusline_style.main_icon,
hl = { hl = {
@ -79,7 +71,7 @@ local get_components = function()
} }, } },
} }
M.file = { local file_name = {
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"
@ -101,7 +93,7 @@ local get_components = function()
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 } },
} }
M.dir = { local dir_name = {
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 .. " "
@ -124,34 +116,49 @@ local get_components = function()
}, },
} }
M.git_added = { local diff = {
add = {
provider = "git_diff_added", provider = "git_diff_added",
hl = { hl = {
fg = colors.grey_fg2, fg = colors.grey_fg2,
bg = colors.statusline_bg, bg = colors.statusline_bg,
}, },
icon = "", icon = "",
} },
M.git_modified = { change = {
provider = "git_diff_changed", provider = "git_diff_changed",
hl = { hl = {
fg = colors.grey_fg2, fg = colors.grey_fg2,
bg = colors.statusline_bg, bg = colors.statusline_bg,
}, },
icon = "", icon = "",
} },
M.git_removed = { remove = {
provider = "git_diff_removed", provider = "git_diff_removed",
hl = { hl = {
fg = colors.grey_fg2, fg = colors.grey_fg2,
bg = colors.statusline_bg, bg = colors.statusline_bg,
}, },
icon = "", icon = "",
},
} }
M.diagnostic_errors = { local git_branch = {
provider = "git_branch",
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
local 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)
@ -159,36 +166,37 @@ local get_components = function()
hl = { fg = colors.red }, hl = { fg = colors.red },
icon = "", icon = "",
} },
M.diagnostic_warnings= { warning = {
provider = "diagnostic_warnings", provider = "diagnostic_warnings",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN) return lsp.diagnostics_exist(lsp_severity.WARN)
end, end,
hl = { fg = colors.yellow }, hl = { fg = colors.yellow },
icon = "", icon = "",
} },
M.diagnostic_hints = { hint = {
provider = "diagnostic_hints", provider = "diagnostic_hints",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT) return lsp.diagnostics_exist(lsp_severity.HINT)
end, end,
hl = { fg = colors.grey_fg2 }, hl = { fg = colors.grey_fg2 },
icon = "", icon = "",
} },
M.dianostic_info ={ 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)
end, end,
hl = { fg = colors.green }, hl = { fg = colors.green },
icon = "", icon = "",
},
} }
M.lsp_progress = { local lsp_progress = {
provider = function() provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1] local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -226,7 +234,7 @@ local get_components = function()
hl = { fg = colors.green }, hl = { fg = colors.green },
} }
M.lsp = { local lsp_icon = {
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"
@ -240,26 +248,6 @@ local get_components = function()
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, hl = { fg = colors.grey_fg2, bg = colors.statusline_bg },
} }
M.git_branch = {
provider = "git_branch",
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
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 }, ["n"] = { "NORMAL", colors.red },
["no"] = { "N-PENDING", colors.red }, ["no"] = { "N-PENDING", colors.red },
@ -290,7 +278,16 @@ local get_components = function()
} }
end end
M.mode_left_separator = { local empty_space = {
provider = " " .. statusline_style.left,
hl = {
fg = colors.one_bg2,
bg = colors.statusline_bg,
},
}
-- this matches the vi mode color
local empty_spaceColored = {
provider = statusline_style.left, provider = statusline_style.left,
hl = function() hl = function()
return { return {
@ -300,7 +297,7 @@ local get_components = function()
end, end,
} }
M.mode_icon = { local mode_icon = {
provider = statusline_style.vi_mode_icon, provider = statusline_style.vi_mode_icon,
hl = function() hl = function()
return { return {
@ -310,14 +307,14 @@ local get_components = function()
end, end,
} }
M.mode_string = { local empty_space2 = {
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,
} }
M.loc_spacer_left = { local separator_right = {
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
@ -325,10 +322,10 @@ local get_components = function()
hl = { hl = {
fg = colors.grey, fg = colors.grey,
bg = colors.one_bg, bg = colors.one_bg,
} },
} }
M.loc_separator_left = { local separator_right2 = {
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
@ -339,7 +336,7 @@ local get_components = function()
}, },
} }
M.loc_position_icon = { local 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
@ -347,10 +344,10 @@ local get_components = function()
hl = { hl = {
fg = colors.black, fg = colors.black,
bg = colors.green, bg = colors.green,
} },
} }
M.loc_position_text = { local current_line = {
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 "$"
@ -373,42 +370,41 @@ local get_components = function()
bg = colors.one_bg, bg = colors.one_bg,
}, },
} }
return M
local function add_table(a, b)
table.insert(a, b)
end end
local components_list = get_components() -- components are divided in 3 sections
local left = {} local left = {}
local right = {}
local middle = {} local middle = {}
local right = {}
table.insert(left, components_list.main_icon) -- left
table.insert(left, components_list.file) add_table(left, main_icon)
table.insert(left, components_list.dir) add_table(left, file_name)
add_table(left, dir_name)
add_table(left, diff.add)
add_table(left, diff.change)
add_table(left, diff.remove)
add_table(left, diagnostic.error)
add_table(left, diagnostic.warning)
add_table(left, diagnostic.hint)
add_table(left, diagnostic.info)
table.insert(left, components_list.git_added) add_table(middle, lsp_progress)
table.insert(left, components_list.git_modified)
table.insert(left, components_list.git_removed)
table.insert(left, components_list.diagnostic_errors) -- right
table.insert(left, components_list.diagnostic_warnings) add_table(right, lsp_icon)
table.insert(left, components_list.diagnostic_hints) add_table(right, git_branch)
table.insert(left, components_list.diagnostic_info) add_table(right, empty_space)
add_table(right, empty_spaceColored)
table.insert(middle, components_list.lsp_progress) add_table(right, mode_icon)
add_table(right, empty_space2)
table.insert(right, components_list.lsp) add_table(right, separator_right)
table.insert(right, components_list.git_branch) add_table(right, separator_right2)
table.insert(right, components_list.git_right_separator) add_table(right, position_icon)
add_table(right, current_line)
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[1] = left
components.active[2] = middle components.active[2] = middle