clean | organize statusline config

This commit is contained in:
siduck 2022-01-11 11:42:02 +05:30
parent fa9f9aad0b
commit a21ee2f22f
1 changed files with 356 additions and 360 deletions

View File

@ -1,4 +1,4 @@
local colors = require("colors").get()
local colors = require("colors").get()
local lsp = require "feline.providers.lsp"
local lsp_severity = vim.diagnostic.severity
@ -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 = {
@ -77,9 +69,9 @@ local get_components = function()
fg = colors.nord_blue,
bg = colors.lightbg,
} },
}
}
M.file = {
local file_name = {
provider = function()
local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e"
@ -99,9 +91,9 @@ 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 .. " "
@ -122,36 +114,51 @@ local get_components = function()
bg = colors.statusline_bg,
},
},
}
}
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]
@ -224,9 +232,9 @@ local get_components = function()
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = { fg = colors.green },
}
}
M.lsp = {
local lsp_icon = {
provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP"
@ -238,29 +246,9 @@ local get_components = function()
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
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 },
["no"] = { "N-PENDING", colors.red },
["i"] = { "INSERT", colors.dark_purple },
@ -281,16 +269,25 @@ local get_components = function()
["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
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 {
@ -298,9 +295,9 @@ local get_components = function()
bg = colors.one_bg2,
}
end,
}
}
M.mode_icon = {
local mode_icon = {
provider = statusline_style.vi_mode_icon,
hl = function()
return {
@ -308,16 +305,16 @@ local get_components = function()
bg = mode_colors[vim.fn.mode()][2],
}
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
@ -337,9 +334,9 @@ local get_components = function()
fg = colors.green,
bg = colors.grey,
},
}
}
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 "$"
@ -372,43 +369,42 @@ local get_components = function()
fg = colors.green,
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