2022-06-05 15:41:26 +02:00
|
|
|
|
local fn = vim.fn
|
2022-06-19 10:13:11 +02:00
|
|
|
|
local sep_style = require("ui.icons").statusline_separators
|
|
|
|
|
local user_sep = require("core.utils").load_config().ui.statusline.separator_style
|
|
|
|
|
local sep_l = sep_style[user_sep]["left"]
|
|
|
|
|
local sep_r = sep_style[user_sep]["right"]
|
2022-06-05 15:41:26 +02:00
|
|
|
|
|
|
|
|
|
local modes = {
|
|
|
|
|
["n"] = { "NORMAL", "St_NormalMode" },
|
2022-06-10 13:54:02 +02:00
|
|
|
|
["niI"] = { "NORMAL i", "St_NormalMode" },
|
|
|
|
|
["niR"] = { "NORMAL r", "St_NormalMode" },
|
|
|
|
|
["niV"] = { "NORMAL v", "St_NormalMode" },
|
2022-06-05 15:41:26 +02:00
|
|
|
|
["no"] = { "N-PENDING", "St_NormalMode" },
|
|
|
|
|
["i"] = { "INSERT", "St_InsertMode" },
|
|
|
|
|
["ic"] = { "INSERT", "St_InsertMode" },
|
2022-06-10 13:54:02 +02:00
|
|
|
|
["ix"] = { "INSERT completion", "St_InsertMode" },
|
2022-06-05 15:41:26 +02:00
|
|
|
|
["t"] = { "TERMINAL", "St_TerminalMode" },
|
|
|
|
|
["nt"] = { "NTERMINAL", "St_NTerminalMode" },
|
|
|
|
|
["v"] = { "VISUAL", "St_VisualMode" },
|
|
|
|
|
["V"] = { "V-LINE", "St_VisualMode" },
|
|
|
|
|
[""] = { "V-BLOCK", "St_VisualMode" },
|
|
|
|
|
["R"] = { "REPLACE", "St_ReplaceMode" },
|
|
|
|
|
["Rv"] = { "V-REPLACE", "St_ReplaceMode" },
|
|
|
|
|
["s"] = { "SELECT", "St_SelectMode" },
|
|
|
|
|
["S"] = { "S-LINE", "St_SelectMode" },
|
|
|
|
|
[""] = { "S-BLOCK", "St_SelectMode" },
|
|
|
|
|
["c"] = { "COMMAND", "St_CommandMode" },
|
|
|
|
|
["cv"] = { "COMMAND", "St_CommandMode" },
|
|
|
|
|
["ce"] = { "COMMAND", "St_CommandMode" },
|
|
|
|
|
["r"] = { "PROMPT", "St_ConfirmMode" },
|
|
|
|
|
["rm"] = { "MORE", "St_ConfirmMode" },
|
|
|
|
|
["r?"] = { "CONFIRM", "St_ConfirmMode" },
|
|
|
|
|
["!"] = { "SHELL", "St_TerminalMode" },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
|
|
M.mode = function()
|
|
|
|
|
local m = vim.api.nvim_get_mode().mode
|
|
|
|
|
local current_mode = "%#" .. modes[m][2] .. "#" .. " " .. modes[m][1]
|
|
|
|
|
local mode_sep1 = "%#" .. modes[m][2] .. "Sep" .. "#" .. sep_r
|
|
|
|
|
|
|
|
|
|
return current_mode .. mode_sep1 .. "%#ST_EmptySpace#" .. sep_r
|
|
|
|
|
end
|
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
M.fileInfo = function()
|
2022-06-14 14:06:27 +02:00
|
|
|
|
local icon = " "
|
2022-06-19 10:13:11 +02:00
|
|
|
|
local filename = (fn.expand "%" == "" and "Empty ") or fn.expand "%:t"
|
2022-06-14 14:06:27 +02:00
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
if filename ~= "Empty " then
|
2022-06-14 14:06:27 +02:00
|
|
|
|
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
2022-06-06 06:40:35 +02:00
|
|
|
|
|
2022-06-14 14:06:27 +02:00
|
|
|
|
if devicons_present then
|
2022-06-24 15:54:59 +02:00
|
|
|
|
local ft_icon = devicons.get_icon(filename)
|
2022-06-14 14:06:27 +02:00
|
|
|
|
icon = (ft_icon ~= nil and " " .. ft_icon) or ""
|
|
|
|
|
end
|
2022-06-05 15:41:26 +02:00
|
|
|
|
|
2022-06-14 14:06:27 +02:00
|
|
|
|
filename = " " .. filename .. " "
|
2022-06-06 02:21:02 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
return "%#St_file_info#" .. icon .. filename .. "%#St_file_sep#" .. sep_r
|
2022-06-05 15:41:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.git = function()
|
|
|
|
|
if not vim.b.gitsigns_head or vim.b.gitsigns_git_status then
|
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local git_status = vim.b.gitsigns_status_dict
|
|
|
|
|
|
|
|
|
|
local added = (git_status.added and git_status.added ~= 0) and (" " .. git_status.added) or ""
|
|
|
|
|
local changed = (git_status.changed and git_status.changed ~= 0) and (" " .. git_status.changed) or ""
|
|
|
|
|
local removed = (git_status.removed and git_status.removed ~= 0) and (" " .. git_status.removed) or ""
|
|
|
|
|
local branch_name = " " .. git_status.head .. " "
|
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
return "%#St_gitIcons#" .. branch_name .. added .. changed .. removed
|
2022-06-05 15:41:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- LSP STUFF
|
|
|
|
|
M.LSP_progress = function()
|
|
|
|
|
local Lsp = vim.lsp.util.get_progress_messages()[1]
|
|
|
|
|
|
2022-06-06 02:21:02 +02:00
|
|
|
|
if vim.o.columns < 120 or not Lsp then
|
2022-06-05 15:41:26 +02:00
|
|
|
|
return ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local msg = Lsp.message or ""
|
|
|
|
|
local percentage = Lsp.percentage or 0
|
|
|
|
|
local title = Lsp.title or ""
|
|
|
|
|
local spinners = { "", "" }
|
|
|
|
|
local ms = vim.loop.hrtime() / 1000000
|
|
|
|
|
local frame = math.floor(ms / 120) % #spinners
|
|
|
|
|
local content = string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
|
|
|
|
|
|
2022-06-06 02:21:02 +02:00
|
|
|
|
return ("%#St_LspProgress#" .. content) or ""
|
2022-06-05 15:41:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.LSP_Diagnostics = function()
|
|
|
|
|
local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
|
|
|
|
|
local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
|
|
|
|
|
local hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT })
|
|
|
|
|
local info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO })
|
|
|
|
|
|
|
|
|
|
errors = (errors and errors > 0) and ("%#St_lspError#" .. " " .. errors .. " ") or ""
|
|
|
|
|
warnings = (warnings and warnings > 0) and ("%#St_lspWarning#" .. " " .. warnings .. " ") or ""
|
|
|
|
|
hints = (hints and hints > 0) and ("%#St_lspHints#" .. "ﯧ " .. hints .. " ") or ""
|
|
|
|
|
info = (info and info > 0) and ("%#St_lspInfo#" .. " " .. info .. " ") or ""
|
|
|
|
|
|
|
|
|
|
return errors .. warnings .. hints .. info
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.LSP_status = function()
|
2022-06-19 10:13:11 +02:00
|
|
|
|
for _, client in ipairs(vim.lsp.get_active_clients()) do
|
2022-06-14 14:06:27 +02:00
|
|
|
|
if client.attached_buffers[vim.api.nvim_get_current_buf()] then
|
2022-06-19 10:13:11 +02:00
|
|
|
|
return (vim.o.columns > 70 and "%#St_LspStatus#" .. " LSP ~ " .. client.name .. " ") or " LSP "
|
2022-06-14 14:06:27 +02:00
|
|
|
|
end
|
2022-06-13 06:39:47 +02:00
|
|
|
|
end
|
2022-06-05 15:41:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.cwd = function()
|
2022-06-09 05:15:28 +02:00
|
|
|
|
local dir_icon = "%#St_cwd_icon#" .. " "
|
2022-06-05 15:41:26 +02:00
|
|
|
|
local dir_name = "%#St_cwd_text#" .. " " .. fn.fnamemodify(fn.getcwd(), ":t") .. " "
|
2022-06-19 13:25:40 +02:00
|
|
|
|
return (vim.o.columns > 120 and ("%#St_cwd_sep#" .. sep_l .. dir_icon .. dir_name)) or ""
|
2022-06-05 15:41:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.cursor_position = function()
|
2022-06-19 10:13:11 +02:00
|
|
|
|
local left_sep = "%#St_pos_sep#" .. sep_l .. "%#St_pos_icon#" .. " "
|
2022-06-05 15:41:26 +02:00
|
|
|
|
|
|
|
|
|
local current_line = fn.line "."
|
|
|
|
|
local total_line = fn.line "$"
|
|
|
|
|
local text = math.modf((current_line / total_line) * 100) .. tostring "%%"
|
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
text = (current_line == 1 and "Top") or text
|
|
|
|
|
text = (current_line == total_line and "Bot") or text
|
2022-06-05 15:41:26 +02:00
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
return left_sep .. "%#St_pos_text#" .. " " .. text .. " "
|
2022-06-05 15:41:26 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.run = function()
|
|
|
|
|
return table.concat {
|
|
|
|
|
M.mode(),
|
2022-06-19 10:13:11 +02:00
|
|
|
|
M.fileInfo(),
|
2022-06-05 15:41:26 +02:00
|
|
|
|
M.git(),
|
|
|
|
|
|
|
|
|
|
"%=",
|
|
|
|
|
M.LSP_progress(),
|
|
|
|
|
"%=",
|
|
|
|
|
|
|
|
|
|
M.LSP_Diagnostics(),
|
2022-06-19 10:13:11 +02:00
|
|
|
|
M.LSP_status() or "",
|
2022-06-05 15:41:26 +02:00
|
|
|
|
M.cwd(),
|
|
|
|
|
M.cursor_position(),
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2022-06-19 10:13:11 +02:00
|
|
|
|
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.statusline.override)
|
|
|
|
|
|
2022-06-05 15:41:26 +02:00
|
|
|
|
return M
|