NvChad/lua/plugins/configs/statusline.lua

439 lines
11 KiB
Lua
Raw Normal View History

local present, feline = pcall(require, "feline")
if not present then
return
end
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 = {
2022-01-11 06:12:02 +00:00
default = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
arrow = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
block = {
left = " ",
right = " ",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
round = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
slant = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
}
-- statusline style
default.statusline_style = default.icon_styles[default.config.style]
2021-11-17 05:30:57 +00:00
-- show short statusline on small screens
default.shortline = default.config.shortline == false and true
2021-08-26 05:18:13 +00:00
-- Initialize the components table
default.components = {
2022-01-11 06:12:02 +00:00
active = {},
}
default.main_icon = {
provider = default.statusline_style.main_icon,
2022-01-11 06:12:02 +00:00
hl = {
fg = default.colors.statusline_bg,
bg = default.colors.nord_blue,
2022-01-11 06:12:02 +00:00
},
right_sep = {
str = default.statusline_style.right,
hl = {
fg = default.colors.nord_blue,
bg = default.colors.lightbg,
},
},
2022-01-11 06:12:02 +00:00
}
default.file_name = {
2022-01-11 06:12:02 +00:00
provider = function()
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 = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = default.colors.white,
bg = default.colors.lightbg,
2022-01-11 06:12:02 +00:00
},
right_sep = {
str = default.statusline_style.right,
hl = { fg = default.colors.lightbg, bg = default.colors.lightbg2 },
},
2022-01-11 06:12:02 +00:00
}
default.dir_name = {
2022-01-11 06:12:02 +00:00
provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " "
end,
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = {
fg = default.colors.grey_fg2,
bg = default.colors.lightbg2,
2022-01-11 06:12:02 +00:00
},
right_sep = {
str = default.statusline_style.right,
2022-01-11 06:12:02 +00:00
hi = {
fg = default.colors.lightbg2,
bg = default.colors.statusline_bg,
2022-01-11 06:12:02 +00:00
},
},
}
default.diff = {
2022-01-11 06:12:02 +00:00
add = {
provider = "git_diff_added",
hl = {
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
2022-01-11 06:12:02 +00:00
},
icon = "",
},
change = {
provider = "git_diff_changed",
hl = {
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
2022-01-11 06:12:02 +00:00
},
icon = "",
},
remove = {
provider = "git_diff_removed",
hl = {
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
2022-01-11 06:12:02 +00:00
},
icon = "",
},
}
default.git_branch = {
2022-01-11 06:12:02 +00:00
provider = "git_branch",
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = {
fg = default.colors.grey_fg2,
bg = default.colors.statusline_bg,
2022-01-11 06:12:02 +00:00
},
icon = "",
}
default.diagnostic = {
2022-01-11 06:12:02 +00:00
errors = {
provider = "diagnostic_errors",
enabled = function()
return default.lsp.diagnostics_exist(default.lsp_severity.ERROR)
2022-01-11 06:12:02 +00:00
end,
hl = { fg = default.colors.red },
2022-01-11 06:12:02 +00:00
icon = "",
},
warning = {
provider = "diagnostic_warnings",
enabled = function()
return default.lsp.diagnostics_exist(default.lsp_severity.WARN)
2022-01-11 06:12:02 +00:00
end,
hl = { fg = default.colors.yellow },
2022-01-11 06:12:02 +00:00
icon = "",
},
hint = {
provider = "diagnostic_hints",
enabled = function()
return default.lsp.diagnostics_exist(default.lsp_severity.HINT)
2022-01-11 06:12:02 +00:00
end,
hl = { fg = default.colors.grey_fg2 },
2022-01-11 06:12:02 +00:00
icon = "",
},
info = {
provider = "diagnostic_info",
enabled = function()
return default.lsp.diagnostics_exist(default.lsp_severity.INFO)
2022-01-11 06:12:02 +00:00
end,
hl = { fg = default.colors.green },
2022-01-11 06:12:02 +00:00
icon = "",
},
}
default.lsp_progress = {
2022-01-11 06:12:02 +00:00
provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1]
if Lsp then
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
if percentage >= 70 then
return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage)
end
return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
end
return ""
end,
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 80
end,
hl = { fg = default.colors.green },
2022-01-11 06:12:02 +00:00
}
default.lsp_icon = {
2022-01-11 06:12:02 +00:00
provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then
return " LSP"
else
return ""
end
end,
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 70
end,
hl = { fg = default.colors.grey_fg2, bg = default.colors.statusline_bg },
2022-01-11 06:12:02 +00:00
}
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 },
2022-01-11 06:12:02 +00:00
}
default.chad_mode_hl = function()
2022-01-11 06:12:02 +00:00
return {
fg = default.mode_colors[vim.fn.mode()][2],
bg = default.colors.one_bg,
2022-01-11 06:12:02 +00:00
}
end
default.empty_space = {
provider = " " .. default.statusline_style.left,
2022-01-11 06:12:02 +00:00
hl = {
fg = default.colors.one_bg2,
bg = default.colors.statusline_bg,
2022-01-11 06:12:02 +00:00
},
}
2022-01-11 06:12:02 +00:00
-- this matches the vi mode color
default.empty_spaceColored = {
provider = default.statusline_style.left,
2022-01-11 06:12:02 +00:00
hl = function()
return {
fg = default.mode_colors[vim.fn.mode()][2],
bg = default.colors.one_bg2,
2022-01-11 06:12:02 +00:00
}
end,
}
default.mode_icon = {
provider = default.statusline_style.vi_mode_icon,
2022-01-11 06:12:02 +00:00
hl = function()
return {
fg = default.colors.statusline_bg,
bg = default.mode_colors[vim.fn.mode()][2],
2022-01-11 06:12:02 +00:00
}
end,
}
default.empty_space2 = {
2022-01-11 06:12:02 +00:00
provider = function()
return " " .. default.mode_colors[vim.fn.mode()][1] .. " "
2022-01-11 06:12:02 +00:00
end,
hl = default.chad_mode_hl,
2022-01-11 06:12:02 +00:00
}
default.separator_right = {
provider = default.statusline_style.left,
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = default.colors.grey,
bg = default.colors.one_bg,
2022-01-11 06:12:02 +00:00
},
}
2021-08-13 06:42:43 +00:00
default.separator_right2 = {
provider = default.statusline_style.left,
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = default.colors.green,
bg = default.colors.grey,
2022-01-11 06:12:02 +00:00
},
}
2021-08-19 12:05:24 +00:00
default.position_icon = {
provider = default.statusline_style.position_icon,
enabled = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = default.colors.black,
bg = default.colors.green,
2022-01-11 06:12:02 +00:00
},
}
2021-08-13 06:42:43 +00:00
default.current_line = {
2022-01-11 06:12:02 +00:00
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 = default.shortline or function(winid)
2022-01-11 06:12:02 +00:00
return vim.api.nvim_win_get_width(tonumber(winid) or 0) > 90
end,
hl = {
fg = default.colors.green,
bg = default.colors.one_bg,
2022-01-11 06:12:02 +00:00
},
}
2022-01-11 06:12:02 +00:00
local function add_table(a, b)
table.insert(a, b)
end
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(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(default.middle, default.lsp_progress)
-- 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)
default.components.active[1] = default.left
default.components.active[2] = default.middle
default.components.active[3] = default.right
feline.setup {
theme = {
bg = default.colors.statusline_bg,
fg = default.colors.fg,
},
components = default.components,
}
end
return M