clean | organize statusline config

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

View File

@ -1,46 +1,46 @@
local colors = require("colors").get() local colors = require("colors").get()
local lsp = require "feline.providers.lsp" local lsp = require "feline.providers.lsp"
local lsp_severity = vim.diagnostic.severity local lsp_severity = vim.diagnostic.severity
local icon_styles = { local icon_styles = {
default = { default = {
left = "", left = "",
right = "", right = "",
main_icon = "", main_icon = "",
vi_mode_icon = "", vi_mode_icon = "",
position_icon = "", position_icon = "",
}, },
arrow = { arrow = {
left = "", left = "",
right = "", right = "",
main_icon = "", main_icon = "",
vi_mode_icon = "", vi_mode_icon = "",
position_icon = "", position_icon = "",
}, },
block = { block = {
left = " ", left = " ",
right = " ", right = " ",
main_icon = "", main_icon = "",
vi_mode_icon = "", vi_mode_icon = "",
position_icon = "", position_icon = "",
}, },
round = { round = {
left = "", left = "",
right = "", right = "",
main_icon = "", main_icon = "",
vi_mode_icon = "", vi_mode_icon = "",
position_icon = "", position_icon = "",
}, },
slant = { slant = {
left = "", left = "",
right = "", right = "",
main_icon = "", main_icon = "",
vi_mode_icon = "", vi_mode_icon = "",
position_icon = "", position_icon = "",
}, },
} }
local config = require("core.utils").load_config().plugins.options.statusline local config = require("core.utils").load_config().plugins.options.statusline
@ -54,370 +54,366 @@ 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, {}) provider = statusline_style.main_icon,
table.insert(components.active, {})
local get_components = function() hl = {
local M = {} fg = colors.statusline_bg,
bg = colors.nord_blue,
},
M.main_icon = { right_sep = { str = statusline_style.right, hl = {
provider = statusline_style.main_icon, fg = colors.nord_blue,
bg = colors.lightbg,
} },
}
hl = { local file_name = {
fg = colors.statusline_bg, provider = function()
bg = colors.nord_blue, local filename = vim.fn.expand "%:t"
}, local extension = vim.fn.expand "%:e"
local icon = require("nvim-web-devicons").get_icon(filename, extension)
if icon == nil then
icon = ""
return icon
end
return " " .. icon .. " " .. filename .. " "
end,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = colors.white,
bg = colors.lightbg,
},
right_sep = { str = statusline_style.right, hl = { right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } },
fg = colors.nord_blue, }
bg = colors.lightbg,
} },
}
M.file = { local dir_name = {
provider = function() provider = function()
local filename = vim.fn.expand "%:t" local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
local extension = vim.fn.expand "%:e" return "" .. dir_name .. " "
local icon = require("nvim-web-devicons").get_icon(filename, extension) end,
if icon == nil then
icon = ""
return icon
end
return " " .. icon .. " " .. filename .. " "
end,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = colors.white,
bg = colors.lightbg,
},
right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } }, enabled = shortline or function(winid)
} return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
M.dir = { hl = {
provider = function() fg = colors.grey_fg2,
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") bg = colors.lightbg2,
return "" .. dir_name .. " " },
end, right_sep = {
str = statusline_style.right,
hi = {
fg = colors.lightbg2,
bg = colors.statusline_bg,
},
},
}
enabled = shortline or function(winid) local diff = {
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 add = {
end, provider = "git_diff_added",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
icon = "",
},
hl = { change = {
fg = colors.grey_fg2, provider = "git_diff_changed",
bg = colors.lightbg2, hl = {
}, fg = colors.grey_fg2,
right_sep = { bg = colors.statusline_bg,
str = statusline_style.right, },
hi = { icon = "",
fg = colors.lightbg2, },
bg = colors.statusline_bg,
},
},
}
M.git_added = { remove = {
provider = "git_diff_added", 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.git_modified = { local git_branch = {
provider = "git_diff_changed", provider = "git_branch",
hl = { enabled = shortline or function(winid)
fg = colors.grey_fg2, return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
bg = colors.statusline_bg, end,
}, hl = {
icon = "", fg = colors.grey_fg2,
} bg = colors.statusline_bg,
},
icon = "",
}
M.git_removed = { local diagnostic = {
provider = "git_diff_removed", errors = {
hl = { provider = "diagnostic_errors",
fg = colors.grey_fg2, enabled = function()
bg = colors.statusline_bg, return lsp.diagnostics_exist(lsp_severity.ERROR)
}, end,
icon = "",
}
M.diagnostic_errors = { hl = { fg = colors.red },
provider = "diagnostic_errors", icon = "",
enabled = function() },
return lsp.diagnostics_exist(lsp_severity.ERROR)
end,
hl = { fg = colors.red }, warning = {
icon = "", provider = "diagnostic_warnings",
} enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN)
end,
hl = { fg = colors.yellow },
icon = "",
},
M.diagnostic_warnings= { hint = {
provider = "diagnostic_warnings", provider = "diagnostic_hints",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN) return lsp.diagnostics_exist(lsp_severity.HINT)
end, end,
hl = { fg = colors.yellow }, hl = { fg = colors.grey_fg2 },
icon = " ", icon = " ",
} },
M.diagnostic_hints = { info = {
provider = "diagnostic_hints", provider = "diagnostic_info",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT) return lsp.diagnostics_exist(lsp_severity.INFO)
end, end,
hl = { fg = colors.grey_fg2 }, hl = { fg = colors.green },
icon = "", icon = "",
} },
}
M.dianostic_info ={ local lsp_progress = {
provider = "diagnostic_info", provider = function()
enabled = function() local Lsp = vim.lsp.util.get_progress_messages()[1]
return lsp.diagnostics_exist(lsp_severity.INFO)
end,
hl = { fg = colors.green },
icon = "",
}
M.lsp_progress = { if Lsp then
provider = function() local msg = Lsp.message or ""
local Lsp = vim.lsp.util.get_progress_messages()[1] local percentage = Lsp.percentage or 0
local title = Lsp.title or ""
local spinners = {
"",
"",
"",
}
if Lsp then local success_icon = {
local msg = Lsp.message or "" "",
local percentage = Lsp.percentage or 0 "",
local title = Lsp.title or "" "",
local spinners = { }
"",
"",
"",
}
local success_icon = { local ms = vim.loop.hrtime() / 1000000
"", local frame = math.floor(ms / 120) % #spinners
"",
"",
}
local ms = vim.loop.hrtime() / 1000000 if percentage >= 70 then
local frame = math.floor(ms / 120) % #spinners return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage)
end
if percentage >= 70 then return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage) end
end
return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage) return ""
end end,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = { fg = colors.green },
}
return "" local lsp_icon = {
end, provider = function()
enabled = shortline or function(winid) if next(vim.lsp.buf_get_clients()) ~= nil then
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80 return " LSP"
end, else
hl = { fg = colors.green }, return ""
} end
end,
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 },
}
M.lsp = { local mode_colors = {
provider = function() ["n"] = { "NORMAL", colors.red },
if next(vim.lsp.buf_get_clients()) ~= nil then ["no"] = { "N-PENDING", colors.red },
return " LSP" ["i"] = { "INSERT", colors.dark_purple },
else ["ic"] = { "INSERT", colors.dark_purple },
return "" ["t"] = { "TERMINAL", colors.green },
end ["v"] = { "VISUAL", colors.cyan },
end, ["V"] = { "V-LINE", colors.cyan },
enabled = shortline or function(winid) [""] = { "V-BLOCK", colors.cyan },
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 ["R"] = { "REPLACE", colors.orange },
end, ["Rv"] = { "V-REPLACE", colors.orange },
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg }, ["s"] = { "SELECT", colors.nord_blue },
} ["S"] = { "S-LINE", colors.nord_blue },
[""] = { "S-BLOCK", colors.nord_blue },
["c"] = { "COMMAND", colors.pink },
["cv"] = { "COMMAND", colors.pink },
["ce"] = { "COMMAND", colors.pink },
["r"] = { "PROMPT", colors.teal },
["rm"] = { "MORE", colors.teal },
["r?"] = { "CONFIRM", colors.teal },
["!"] = { "SHELL", colors.green },
}
M.git_branch = { local chad_mode_hl = function()
provider = "git_branch", return {
enabled = shortline or function(winid) fg = mode_colors[vim.fn.mode()][2],
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70 bg = colors.one_bg,
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 },
["i"] = { "INSERT", colors.dark_purple },
["ic"] = { "INSERT", colors.dark_purple },
["t"] = { "TERMINAL", colors.green },
["v"] = { "VISUAL", colors.cyan },
["V"] = { "V-LINE", colors.cyan },
[""] = { "V-BLOCK", colors.cyan },
["R"] = { "REPLACE", colors.orange },
["Rv"] = { "V-REPLACE", colors.orange },
["s"] = { "SELECT", colors.nord_blue },
["S"] = { "S-LINE", colors.nord_blue },
[""] = { "S-BLOCK", colors.nord_blue },
["c"] = { "COMMAND", colors.pink },
["cv"] = { "COMMAND", colors.pink },
["ce"] = { "COMMAND", colors.pink },
["r"] = { "PROMPT", colors.teal },
["rm"] = { "MORE", colors.teal },
["r?"] = { "CONFIRM", colors.teal },
["!"] = { "SHELL", colors.green },
}
local chad_mode_hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg,
}
end
M.mode_left_separator = {
provider = statusline_style.left,
hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg2,
}
end,
}
M.mode_icon = {
provider = statusline_style.vi_mode_icon,
hl = function()
return {
fg = colors.statusline_bg,
bg = mode_colors[vim.fn.mode()][2],
}
end,
}
M.mode_string = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
end,
hl = chad_mode_hl,
}
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
end,
hl = {
fg = colors.grey,
bg = colors.one_bg,
}
}
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
end,
hl = {
fg = colors.green,
bg = colors.grey,
},
}
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
end,
hl = {
fg = colors.black,
bg = colors.green,
}
}
M.loc_position_text = {
provider = function()
local current_line = vim.fn.line "."
local total_line = vim.fn.line "$"
if current_line == 1 then
return " Top "
elseif current_line == vim.fn.line "$" then
return " Bot "
end
local result, _ = math.modf((current_line / total_line) * 100)
return " " .. result .. "%% "
end,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = colors.green,
bg = colors.one_bg,
},
}
return M
end end
local components_list = get_components() 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 {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg2,
}
end,
}
local mode_icon = {
provider = statusline_style.vi_mode_icon,
hl = function()
return {
fg = colors.statusline_bg,
bg = mode_colors[vim.fn.mode()][2],
}
end,
}
local empty_space2 = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
end,
hl = chad_mode_hl,
}
local separator_right = {
provider = statusline_style.left,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = colors.grey,
bg = colors.one_bg,
},
}
local separator_right2 = {
provider = statusline_style.left,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = colors.green,
bg = colors.grey,
},
}
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
end,
hl = {
fg = colors.black,
bg = colors.green,
},
}
local current_line = {
provider = function()
local current_line = vim.fn.line "."
local total_line = vim.fn.line "$"
if current_line == 1 then
return " Top "
elseif current_line == vim.fn.line "$" then
return " Bot "
end
local result, _ = math.modf((current_line / total_line) * 100)
return " " .. result .. "%% "
end,
enabled = shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = colors.green,
bg = colors.one_bg,
},
}
local function add_table(a, b)
table.insert(a, b)
end
-- 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
components.active[3] = right components.active[3] = right
require("feline").setup { require("feline").setup {
theme = { theme = {
bg = colors.statusline_bg, bg = colors.statusline_bg,
fg = colors.fg, fg = colors.fg,
}, },
components = components, components = components,
} }