utils: Improve override functions | Fix nvimtree and statusline config |

Misc

* make more things configurable
* use more generic variable names
* handle some edgecases
* cleanup
* format files
This commit is contained in:
Akianonymus 2022-01-21 17:19:49 +05:30 committed by siduck
parent 82211ed829
commit bccd8e4ab9
10 changed files with 338 additions and 317 deletions

View file

@ -1,8 +1,16 @@
local colors = require("colors").get()
local lsp = require "feline.providers.lsp"
local lsp_severity = vim.diagnostic.severity
local present, feline = pcall(require, "feline")
if not present then
return
end
local icon_styles = {
local default = {
colors = require("colors").get(),
lsp = require "feline.providers.lsp",
lsp_severity = vim.diagnostic.severity,
config = require("core.utils").load_config().plugins.options.statusline,
}
default.icon_styles = {
default = {
left = "",
right = "",
@ -43,35 +51,35 @@ local icon_styles = {
},
}
local config = require("core.utils").load_config().plugins.options.statusline
-- statusline style
local user_statusline_style = config.style
local statusline_style = icon_styles[user_statusline_style]
default.statusline_style = default.icon_styles[default.config.style]
-- show short statusline on small screens
local shortline = config.shortline == false and true
default.shortline = default.config.shortline == false and true
-- Initialize the components table
local components = {
default.components = {
active = {},
}
local main_icon = {
provider = statusline_style.main_icon,
default.main_icon = {
provider = default.statusline_style.main_icon,
hl = {
fg = colors.statusline_bg,
bg = colors.nord_blue,
fg = default.colors.statusline_bg,
bg = default.colors.nord_blue,
},
right_sep = { str = statusline_style.right, hl = {
fg = colors.nord_blue,
bg = colors.lightbg,
} },
right_sep = {
str = default.statusline_style.right,
hl = {
fg = default.colors.nord_blue,
bg = default.colors.lightbg,
},
},
}
local file_name = {
default.file_name = {
provider = function()
local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e"
@ -82,46 +90,49 @@ local file_name = {
end
return " " .. icon .. " " .. filename .. " "
end,
enabled = shortline or function(winid)
enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = colors.white,
bg = colors.lightbg,
fg = default.colors.white,
bg = default.colors.lightbg,
},
right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } },
right_sep = {
str = default.statusline_style.right,
hl = { fg = default.colors.lightbg, bg = default.colors.lightbg2 },
},
}
local dir_name = {
default.dir_name = {
provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " "
end,
enabled = shortline or function(winid)
enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = {
fg = colors.grey_fg2,
bg = colors.lightbg2,
fg = default.colors.grey_fg2,
bg = default.colors.lightbg2,
},
right_sep = {
str = statusline_style.right,
str = default.statusline_style.right,
hi = {
fg = colors.lightbg2,
bg = colors.statusline_bg,
fg = default.colors.lightbg2,
bg = default.colors.statusline_bg,
},
},
}
local diff = {
default.diff = {
add = {
provider = "git_diff_added",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
},
icon = "",
},
@ -129,8 +140,8 @@ local diff = {
change = {
provider = "git_diff_changed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
},
icon = "",
},
@ -138,65 +149,65 @@ local diff = {
remove = {
provider = "git_diff_removed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
},
icon = "",
},
}
local git_branch = {
default.git_branch = {
provider = "git_branch",
enabled = shortline or function(winid)
enabled = default.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,
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
},
icon = "",
}
local diagnostic = {
default.diagnostic = {
errors = {
provider = "diagnostic_errors",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR)
return default.lsp.diagnostics_exist(default.lsp_severity.ERROR)
end,
hl = { fg = colors.red },
hl = { fg = default.colors.red },
icon = "",
},
warning = {
provider = "diagnostic_warnings",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN)
return default.lsp.diagnostics_exist(default.lsp_severity.WARN)
end,
hl = { fg = colors.yellow },
hl = { fg = default.colors.yellow },
icon = "",
},
hint = {
provider = "diagnostic_hints",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT)
return default.lsp.diagnostics_exist(default.lsp_severity.HINT)
end,
hl = { fg = colors.grey_fg2 },
hl = { fg = default.colors.grey_fg2 },
icon = "",
},
info = {
provider = "diagnostic_info",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO)
return default.lsp.diagnostics_exist(default.lsp_severity.INFO)
end,
hl = { fg = colors.green },
hl = { fg = default.colors.green },
icon = "",
},
}
local lsp_progress = {
default.lsp_progress = {
provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -228,13 +239,13 @@ local lsp_progress = {
return ""
end,
enabled = shortline or function(winid)
enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = { fg = colors.green },
hl = { fg = default.colors.green },
}
local lsp_icon = {
default.lsp_icon = {
provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP"
@ -242,112 +253,112 @@ local lsp_icon = {
return ""
end
end,
enabled = shortline or function(winid)
enabled = default.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 },
hl = { fg = default.colors.grey_fg2, bg = default.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 },
default.mode_colors = {
["n"] = { "NORMAL", default.colors.red },
["no"] = { "N-PENDING", default.colors.red },
["i"] = { "INSERT", default.colors.dark_purple },
["ic"] = { "INSERT", default.colors.dark_purple },
["t"] = { "TERMINAL", default.colors.green },
["v"] = { "VISUAL", default.colors.cyan },
["V"] = { "V-LINE", default.colors.cyan },
[""] = { "V-BLOCK", default.colors.cyan },
["R"] = { "REPLACE", default.colors.orange },
["Rv"] = { "V-REPLACE", default.colors.orange },
["s"] = { "SELECT", default.colors.nord_blue },
["S"] = { "S-LINE", default.colors.nord_blue },
[""] = { "S-BLOCK", default.colors.nord_blue },
["c"] = { "COMMAND", default.colors.pink },
["cv"] = { "COMMAND", default.colors.pink },
["ce"] = { "COMMAND", default.colors.pink },
["r"] = { "PROMPT", default.colors.teal },
["rm"] = { "MORE", default.colors.teal },
["r?"] = { "CONFIRM", default.colors.teal },
["!"] = { "SHELL", default.colors.green },
}
local chad_mode_hl = function()
default.chad_mode_hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg,
fg = default.mode_colors[vim.fn.mode()][2],
bg = default.colors.one_bg,
}
end
local empty_space = {
provider = " " .. statusline_style.left,
default.empty_space = {
provider = " " .. default.statusline_style.left,
hl = {
fg = colors.one_bg2,
bg = colors.statusline_bg,
fg = default.colors.one_bg2,
bg = default.colors.statusline_bg,
},
}
-- this matches the vi mode color
local empty_spaceColored = {
provider = statusline_style.left,
default.empty_spaceColored = {
provider = default.statusline_style.left,
hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg2,
fg = default.mode_colors[vim.fn.mode()][2],
bg = default.colors.one_bg2,
}
end,
}
local mode_icon = {
provider = statusline_style.vi_mode_icon,
default.mode_icon = {
provider = default.statusline_style.vi_mode_icon,
hl = function()
return {
fg = colors.statusline_bg,
bg = mode_colors[vim.fn.mode()][2],
fg = default.colors.statusline_bg,
bg = default.mode_colors[vim.fn.mode()][2],
}
end,
}
local empty_space2 = {
default.empty_space2 = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
return " " .. default.mode_colors[vim.fn.mode()][1] .. " "
end,
hl = chad_mode_hl,
hl = default.chad_mode_hl,
}
local separator_right = {
provider = statusline_style.left,
enabled = shortline or function(winid)
default.separator_right = {
provider = default.statusline_style.left,
enabled = default.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,
fg = default.colors.grey,
bg = default.colors.one_bg,
},
}
local separator_right2 = {
provider = statusline_style.left,
enabled = shortline or function(winid)
default.separator_right2 = {
provider = default.statusline_style.left,
enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = colors.green,
bg = colors.grey,
fg = default.colors.green,
bg = default.colors.grey,
},
}
local position_icon = {
provider = statusline_style.position_icon,
enabled = shortline or function(winid)
default.position_icon = {
provider = default.statusline_style.position_icon,
enabled = default.shortline or function(winid)
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = colors.black,
bg = colors.green,
fg = default.colors.black,
bg = default.colors.green,
},
}
local current_line = {
default.current_line = {
provider = function()
local current_line = vim.fn.line "."
local total_line = vim.fn.line "$"
@ -361,13 +372,13 @@ local current_line = {
return " " .. result .. "%% "
end,
enabled = shortline or function(winid)
enabled = default.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,
fg = default.colors.green,
bg = default.colors.one_bg,
},
}
@ -375,45 +386,53 @@ local function add_table(a, b)
table.insert(a, b)
end
-- components are divided in 3 sections
local left = {}
local middle = {}
local right = {}
local M = {}
M.setup = function(override_flag)
if override_flag then
default = require("core.utils").tbl_override_req("feline", default)
end
-- components are divided in 3 sections
default.left = {}
default.middle = {}
default.right = {}
-- 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)
-- left
add_table(default.left, default.main_icon)
add_table(default.left, default.file_name)
add_table(default.left, default.dir_name)
add_table(default.left, default.diff.add)
add_table(default.left, default.diff.change)
add_table(default.left, default.diff.remove)
add_table(default.left, default.diagnostic.error)
add_table(default.left, default.diagnostic.warning)
add_table(default.left, default.diagnostic.hint)
add_table(default.left, default.diagnostic.info)
add_table(middle, lsp_progress)
add_table(default.middle, default.lsp_progress)
-- 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)
-- right
add_table(default.right, default.lsp_icon)
add_table(default.right, default.git_branch)
add_table(default.right, default.empty_space)
add_table(default.right, default.empty_spaceColored)
add_table(default.right, default.mode_icon)
add_table(default.right, default.empty_space2)
add_table(default.right, default.separator_right)
add_table(default.right, default.separator_right2)
add_table(default.right, default.position_icon)
add_table(default.right, default.current_line)
components.active[1] = left
components.active[2] = middle
components.active[3] = right
default.components.active[1] = default.left
default.components.active[2] = default.middle
default.components.active[3] = default.right
require("feline").setup {
theme = {
bg = colors.statusline_bg,
fg = colors.fg,
},
components = components,
}
feline.setup {
theme = {
bg = default.colors.statusline_bg,
fg = default.colors.fg,
},
components = default.components,
}
end
return M