1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
-- =====================================================
-- Native Statusline Implementation
-- Replacement for lualine.nvim
-- =====================================================
local M = {}
-- Import colors from our native colorscheme
local function get_colors()
local ok, colorscheme = pcall(require, "config.native-colorscheme")
if ok then
return colorscheme.colors
end
-- Fallback colors
return {
base03 = "#16161e",
fg = "#c0caf5",
blue100 = "#9bb3f7",
green100 = "#b3d882",
yellow100 = "#e7c664",
orange100 = "#ffad7a",
red100 = "#ff7a93",
cyan100 = "#7dd3c0",
magenta100 = "#d2a8ff",
base4 = "#c0caf5",
green300 = "#9ece6a",
yellow300 = "#e0af68",
red300 = "#f7768e",
blue300 = "#7aa2f7",
cyan300 = "#73daca",
orange300 = "#ff9e64",
}
end
local colors = get_colors()
-- Helper function to create highlight groups
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
end
vim.api.nvim_set_hl(0, name, hl)
return "%#" .. name .. "#"
end
-- Define statusline highlight groups
local function setup_highlights()
create_highlight("StatuslineModeNormal", colors.blue100, colors.base03, "bold")
create_highlight("StatuslineModeInsert", colors.green100, colors.base03, "bold")
create_highlight("StatuslineModeVisual", colors.magenta100, colors.base03, "bold")
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", " " },
v = { "VISUAL", "StatuslineModeVisual", " " },
V = { "V-LINE", "StatuslineModeVisual", " " },
[""] = { "V-BLOCK", "StatuslineModeVisual", " " },
c = { "COMMAND", "StatuslineModeCommand", " " },
R = { "REPLACE", "StatuslineModeReplace", " " },
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")
handle:close()
if not branch or branch == "" then
return ""
end
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")
handle:close()
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
-- 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 result = ""
if tonumber(added) and tonumber(added) > 0 then
result = result .. "%#StatuslineGitAdd# +" .. added .. " "
end
if tonumber(modified) and tonumber(modified) > 0 then
result = result .. "%#StatuslineGitChange# ~" .. modified .. " "
end
return result
end
-- Get filename with path
local function get_filename()
local filename = vim.fn.expand("%:t")
if filename == "" then
filename = "[No Name]"
end
return "%#StatuslineFilename# " .. filename .. " "
end
-- Get LSP clients
local function get_lsp_clients()
local clients = vim.lsp.get_clients({ bufnr = 0 })
if #clients == 0 then
return "%#StatuslineLSP#No LSP "
end
local client_names = {}
for _, client in ipairs(clients) do
table.insert(client_names, client.name)
end
return "%#StatuslineLSP#" .. 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
elseif diagnostic.severity == vim.diagnostic.severity.WARN then
counts.warn = counts.warn + 1
elseif diagnostic.severity == vim.diagnostic.severity.INFO then
counts.info = counts.info + 1
elseif diagnostic.severity == vim.diagnostic.severity.HINT then
counts.hint = counts.hint + 1
end
end
local result = ""
if counts.error > 0 then
result = result .. "%#StatuslineDiagError# " .. counts.error .. " "
end
if counts.warn > 0 then
result = result .. "%#StatuslineDiagWarn# " .. counts.warn .. " "
end
if counts.info > 0 then
result = result .. "%#StatuslineDiagInfo# " .. counts.info .. " "
end
if counts.hint > 0 then
result = result .. "%#StatuslineDiagHint# " .. counts.hint .. " "
end
return result
end
-- Get filetype
local function get_filetype()
local filetype = vim.bo.filetype
if filetype == "" then
return ""
end
return "%#StatuslineFiletype#" .. filetype .. " "
end
-- Get progress (line/total)
local function get_progress()
local current = vim.fn.line(".")
local total = vim.fn.line("$")
local percentage = math.floor((current / total) * 100)
return "%#StatuslineProgress#" .. percentage .. "%% "
end
-- Get separator
local function separator()
return "%#StatuslineSeparator# "
end
-- Build the statusline
function M.build_statusline()
local left = get_mode() .. separator() ..
get_git_branch() .. separator() ..
get_git_diff() .. separator()
|