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
local components = {
active = {},
inactive = {},
}
table.insert(components.active, {})
table.insert(components.active, {})
table.insert(components.active, {})
local get_components = function()
local M = {}
M.main_icon = {
local main_icon = {
provider = statusline_style.main_icon,
hl = {
@ -79,7 +71,7 @@ local get_components = function()
} },
}
M.file = {
local file_name = {
provider = function()
local filename = vim.fn.expand "%:t"
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 } },
}
M.dir = {
local dir_name = {
provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " "
@ -124,34 +116,49 @@ local get_components = function()
},
}
M.git_added = {
local diff = {
add = {
provider = "git_diff_added",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
},
M.git_modified = {
change = {
provider = "git_diff_changed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
}
},
M.git_removed = {
remove = {
provider = "git_diff_removed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
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",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR)
@ -159,36 +166,37 @@ local get_components = function()
hl = { fg = colors.red },
icon = "",
}
},
M.diagnostic_warnings= {
warning = {
provider = "diagnostic_warnings",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN)
end,
hl = { fg = colors.yellow },
icon = "",
}
},
M.diagnostic_hints = {
hint = {
provider = "diagnostic_hints",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT)
end,
hl = { fg = colors.grey_fg2 },
icon = "",
}
},
M.dianostic_info ={
info = {
provider = "diagnostic_info",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO)
end,
hl = { fg = colors.green },
icon = "",
},
}
M.lsp_progress = {
local lsp_progress = {
provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -226,7 +234,7 @@ local get_components = function()
hl = { fg = colors.green },
}
M.lsp = {
local lsp_icon = {
provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP"
@ -240,26 +248,6 @@ local get_components = function()
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 = {
["n"] = { "NORMAL", colors.red },
["no"] = { "N-PENDING", colors.red },
@ -290,7 +278,16 @@ local get_components = function()
}
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,
hl = function()
return {
@ -300,7 +297,7 @@ local get_components = function()
end,
}
M.mode_icon = {
local mode_icon = {
provider = statusline_style.vi_mode_icon,
hl = function()
return {
@ -310,14 +307,14 @@ local get_components = function()
end,
}
M.mode_string = {
local empty_space2 = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
end,
hl = chad_mode_hl,
}
M.loc_spacer_left = {
local separator_right = {
provider = statusline_style.left,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -325,10 +322,10 @@ local get_components = function()
hl = {
fg = colors.grey,
bg = colors.one_bg,
}
},
}
M.loc_separator_left = {
local separator_right2 = {
provider = statusline_style.left,
enabled = shortline or function(winid)
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,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
@ -347,10 +344,10 @@ local get_components = function()
hl = {
fg = colors.black,
bg = colors.green,
}
},
}
M.loc_position_text = {
local current_line = {
provider = function()
local current_line = vim.fn.line "."
local total_line = vim.fn.line "$"
@ -373,42 +370,41 @@ local get_components = function()
bg = colors.one_bg,
},
}
return M
local function add_table(a, b)
table.insert(a, b)
end
local components_list = get_components()
-- components are divided in 3 sections
local left = {}
local right = {}
local middle = {}
local right = {}
table.insert(left, components_list.main_icon)
table.insert(left, components_list.file)
table.insert(left, components_list.dir)
-- left
add_table(left, main_icon)
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)
table.insert(left, components_list.git_modified)
table.insert(left, components_list.git_removed)
add_table(middle, lsp_progress)
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)
-- right
add_table(right, lsp_icon)
add_table(right, git_branch)
add_table(right, empty_space)
add_table(right, empty_spaceColored)
add_table(right, mode_icon)
add_table(right, empty_space2)
add_table(right, separator_right)
add_table(right, separator_right2)
add_table(right, position_icon)
add_table(right, current_line)
components.active[1] = left
components.active[2] = middle