aboutsummaryrefslogtreecommitdiffstats
path: root/lua/config/native-statusline.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/config/native-statusline.lua')
-rw-r--r--lua/config/native-statusline.lua185
1 files changed, 117 insertions, 68 deletions
diff --git a/lua/config/native-statusline.lua b/lua/config/native-statusline.lua
index c7dea6e..61ac97a 100644
--- a/lua/config/native-statusline.lua
+++ b/lua/config/native-statusline.lua
@@ -38,8 +38,12 @@ local colors = get_colors()
local function create_highlight(name, fg, bg, style)
local hl = { fg = fg, bg = bg }
if style then
- if style:find("bold") then hl.bold = true end
- if style:find("italic") then hl.italic = true end
+ if style:find "bold" then
+ hl.bold = true
+ end
+ if style:find "italic" then
+ hl.italic = true
+ end
end
vim.api.nvim_set_hl(0, name, hl)
return "%#" .. name .. "#"
@@ -53,93 +57,103 @@ local function setup_highlights()
create_highlight("StatuslineModeReplace", colors.red100, colors.base03, "bold")
create_highlight("StatuslineModeCommand", colors.yellow100, colors.base03, "bold")
create_highlight("StatuslineModeTerminal", colors.orange100, colors.base03, "bold")
-
+
create_highlight("StatuslineBranch", colors.orange100, colors.base03, "bold")
create_highlight("StatuslineFilename", colors.yellow100, colors.base03, "bold")
create_highlight("StatuslineLSP", colors.base4, colors.base03, "bold")
create_highlight("StatuslineFiletype", colors.magenta100, colors.base03, "bold")
create_highlight("StatuslineProgress", colors.cyan100, colors.base03, "bold")
-
+
create_highlight("StatuslineGitAdd", colors.green300, colors.base03, "bold")
create_highlight("StatuslineGitChange", colors.yellow300, colors.base03, "bold")
create_highlight("StatuslineGitDelete", colors.red300, colors.base03, "bold")
-
+
create_highlight("StatuslineDiagError", colors.red300, colors.base03, "bold")
create_highlight("StatuslineDiagWarn", colors.yellow300, colors.base03, "bold")
create_highlight("StatuslineDiagInfo", colors.blue300, colors.base03, "bold")
create_highlight("StatuslineDiagHint", colors.cyan300, colors.base03, "bold")
-
+
create_highlight("StatuslineSeparator", colors.base03, colors.base03, "")
end
-- Get current mode
local function get_mode()
local mode_map = {
- n = { "NORMAL", "StatuslineModeNormal", " " },
- i = { "INSERT", "StatuslineModeInsert", " " },
+ n = { "NORMAL", "StatuslineModeNormal", " " },
+ i = { "INSERT", "StatuslineModeInsert", " " },
v = { "VISUAL", "StatuslineModeVisual", "󰈈 " },
- V = { "V-LINE", "StatuslineModeVisual", " " },
- [""] = { "V-BLOCK", "StatuslineModeVisual", "󰩭 " },
- c = { "COMMAND", "StatuslineModeCommand", " " },
+ V = { "V-LINE", "StatuslineModeVisual", "󰕞 " },
+ ["\22"] = { "V-BLOCK", "StatuslineModeVisual", "󰩭 " }, -- Ctrl+v visual block mode
+ c = { "COMMAND", "StatuslineModeCommand", " " },
R = { "REPLACE", "StatuslineModeReplace", "󰛔 " },
- t = { "TERMINAL", "StatuslineModeTerminal", " " },
+ t = { "TERMINAL", "StatuslineModeTerminal", " " },
}
-
+
local current_mode = vim.fn.mode()
local mode_info = mode_map[current_mode] or { "UNKNOWN", "StatuslineModeNormal", " " }
-
+
return "%#" .. mode_info[2] .. "#" .. mode_info[3] .. mode_info[1] .. " "
end
-- Get git branch
local function get_git_branch()
- local handle = io.popen("git branch --show-current 2>/dev/null")
- if not handle then return "" end
-
- local branch = handle:read("*l")
+ local handle = io.popen "git branch --show-current 2>/dev/null"
+ if not handle then
+ return ""
+ end
+
+ local branch = handle:read "*l"
handle:close()
-
+
if not branch or branch == "" then
return ""
end
- return "%#StatuslineBranch# " .. branch .. " "
+ return "%#StatuslineBranch# " .. "  " .. branch .. " "
end
-- Get git diff stats
local function get_git_diff()
-- Check if we're in a git repository
- local handle = io.popen("git rev-parse --is-inside-work-tree 2>/dev/null")
- if not handle then return "" end
-
- local is_git = handle:read("*l")
+ local handle = io.popen "git rev-parse --is-inside-work-tree 2>/dev/null"
+ if not handle then
+ return ""
+ end
+
+ local is_git = handle:read "*l"
handle:close()
-
- if is_git ~= "true" then return "" end
-
+
+ if is_git ~= "true" then
+ return ""
+ end
+
-- Get staged changes
- local staged_handle = io.popen("git diff --cached --numstat 2>/dev/null | wc -l")
- local added = staged_handle and staged_handle:read("*l") or "0"
- if staged_handle then staged_handle:close() end
-
+ local staged_handle = io.popen "git diff --cached --numstat 2>/dev/null | wc -l"
+ local added = staged_handle and staged_handle:read "*l" or "0"
+ if staged_handle then
+ staged_handle:close()
+ end
+
-- Get unstaged changes
- local unstaged_handle = io.popen("git diff --numstat 2>/dev/null | wc -l")
- local modified = unstaged_handle and unstaged_handle:read("*l") or "0"
- if unstaged_handle then unstaged_handle:close() end
-
+ local unstaged_handle = io.popen "git diff --numstat 2>/dev/null | wc -l"
+ local modified = unstaged_handle and unstaged_handle:read "*l" or "0"
+ if unstaged_handle then
+ unstaged_handle:close()
+ end
+
local result = ""
if tonumber(added) and tonumber(added) > 0 then
- result = result .. "%#StatuslineGitAdd# +" .. added .. " "
+ result = result .. "%#StatuslineGitAdd#  +" .. added .. " "
end
if tonumber(modified) and tonumber(modified) > 0 then
- result = result .. "%#StatuslineGitChange# ~" .. modified .. " "
+ result = result .. "%#StatuslineGitChange#  ~" .. modified .. " "
end
-
+
return result
end
-- Get filename with path
local function get_filename()
- local filename = vim.fn.expand("%:t")
+ local filename = vim.fn.expand "%:t"
if filename == "" then
filename = "[No Name]"
end
@@ -148,24 +162,52 @@ end
-- Get LSP clients
local function get_lsp_clients()
- local clients = vim.lsp.get_clients({ bufnr = 0 })
+ local clients = vim.lsp.get_clients { bufnr = 0 }
if #clients == 0 then
return "%#StatuslineLSP#No LSP "
end
-
+
+ -- Map common LSP names to icons (nerdfonts / devicons style). Add or adjust as you like.
+ local lsp_icons = {
+ lua_ls = "",
+ sumneko_lua = "",
+ pyright = "",
+ pylsp = "",
+ tsserver = "",
+ denols = "",
+ rust_analyzer = "",
+ gopls = "",
+ clangd = "",
+ html = "󰜫",
+ cssls = "",
+ bashls = "",
+ jsonls = "ﬥ",
+ tailwindcss = "",
+ angularls = "",
+ emmet_ls = "",
+ ["null-ls"] = "ﳠ",
+ copilot = "",
+ }
+
+ local seen = {}
local client_names = {}
for _, client in ipairs(clients) do
- table.insert(client_names, client.name)
+ local name = client.name or "unknown"
+ if not seen[name] then
+ seen[name] = true
+ local icon = lsp_icons[name] or ""
+ table.insert(client_names, icon .. " " .. name)
+ end
end
-
- return "%#StatuslineLSP#" .. table.concat(client_names, ",") .. " "
+
+ return "%#StatuslineLSP#" .. "LSP: " .. table.concat(client_names, ", ") .. " "
end
-- Get diagnostics
local function get_diagnostics()
local diagnostics = vim.diagnostic.get(0)
local counts = { error = 0, warn = 0, info = 0, hint = 0 }
-
+
for _, diagnostic in ipairs(diagnostics) do
if diagnostic.severity == vim.diagnostic.severity.ERROR then
counts.error = counts.error + 1
@@ -177,21 +219,23 @@ local function get_diagnostics()
counts.hint = counts.hint + 1
end
end
-
+
local result = ""
+
+ -- Add icons for each diagnostic type (uses nerdfonts/devicons where available)
if counts.error > 0 then
- result = result .. "%#StatuslineDiagError# " .. counts.error .. " "
+ result = result .. "%#StatuslineDiagError#  " .. counts.error .. " "
end
if counts.warn > 0 then
- result = result .. "%#StatuslineDiagWarn# " .. counts.warn .. " "
+ result = result .. "%#StatuslineDiagWarn#  " .. counts.warn .. " "
end
if counts.info > 0 then
- result = result .. "%#StatuslineDiagInfo# " .. counts.info .. " "
+ result = result .. "%#StatuslineDiagInfo#  " .. counts.info .. " "
end
if counts.hint > 0 then
- result = result .. "%#StatuslineDiagHint#󰠠 " .. counts.hint .. " "
+ result = result .. "%#StatuslineDiagHint# 󰠠 " .. counts.hint .. " "
end
-
+
return result
end
@@ -206,8 +250,8 @@ end
-- Get progress (line/total)
local function get_progress()
- local current = vim.fn.line(".")
- local total = vim.fn.line("$")
+ local current = vim.fn.line "."
+ local total = vim.fn.line "$"
local percentage = math.floor((current / total) * 100)
return "%#StatuslineProgress#" .. percentage .. "%% "
end
@@ -219,39 +263,44 @@ end
-- Build the statusline
function M.build_statusline()
- local left = get_mode() .. separator() ..
- get_git_branch() .. separator() ..
- get_git_diff() .. separator() ..
- get_filename()
-
- local right = get_diagnostics() .. separator() ..
- get_lsp_clients() .. separator() ..
- get_filetype() .. separator() ..
- get_progress()
-
+ local left = get_mode()
+ .. separator()
+ .. get_git_branch()
+ .. separator()
+ .. get_git_diff()
+ .. separator()
+ .. get_filetype()
+ .. get_filename()
+
+ local right = get_diagnostics() .. separator() .. get_lsp_clients() .. separator() .. get_progress()
+
return left .. "%=" .. right
end
-- Setup function
function M.setup()
setup_highlights()
-
+
-- Set up autocommands to refresh statusline
vim.api.nvim_create_augroup("NativeStatusline", { clear = true })
-
+
-- Update statusline on various events
vim.api.nvim_create_autocmd({
- "VimEnter", "WinEnter", "BufEnter", "ModeChanged", "DiagnosticChanged"
+ "VimEnter",
+ "WinEnter",
+ "BufEnter",
+ "ModeChanged",
+ "DiagnosticChanged",
}, {
group = "NativeStatusline",
callback = function()
vim.opt.statusline = M.build_statusline()
end,
})
-
+
-- Set initial statusline
vim.opt.statusline = M.build_statusline()
-
+
-- Always show statusline
vim.opt.laststatus = 2
end