forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeline.lua
More file actions
506 lines (459 loc) · 10.8 KB
/
feline.lua
File metadata and controls
506 lines (459 loc) · 10.8 KB
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
-- Plugin: feline
-- https://github.com/feline-nvim/feline.nvim
return {
-----------------------------------------------------------
{
'feline-nvim/feline.nvim',
enabled = false,
event = 'VeryLazy',
opts = function()
local icons = require("config.icons")
local present, feline = pcall(require, "feline")
local fmt = string.format
if not present then
return
end
local theme = {
glacier = "#81A1C1", -- nord9 in palette
bg = "#2E3440",
black = "#2E3440", -- nord0 in palette
blue = "#5E81AC", -- nord10 in palette
teal = "#8FBCBB", -- nord7 in palette
red = "#BF616A", -- nord11 in palette
fg = "#ECEFF4", -- nord6 in palette
white = "#ECEFF4", -- nord6 in palette
dark_gray = "#3B4252", -- nord1 in palette
gray = "#434C5E", -- nord2 in palette
light_gray = "#4C566A", -- nord3 in palette
light_gray_bright = "#616E88", -- out of palette
darkest_white = "#D8DEE9", -- nord4 in palette
darker_white = "#E5E9F0", -- nord5 in palette
green = "#A3BE8C", -- nord14 in palette
off_blue = "#88C0D0", -- nord8 in palette
orange = "#D08770", -- nord12 in palette
purple = "#B48EAD", -- nord15 in palette
yellow = "#EBCB8B",
}
vim.api.nvim_set_hl(0, "StatusLine", { bg = "#434C5E", fg = "#D8DEE9" })
local mode_theme = {
["NORMAL"] = theme.glacier,
["OP"] = theme.teal,
["INSERT"] = theme.fg,
["VISUAL"] = theme.off_blue,
["LINES"] = theme.red,
["BLOCK"] = theme.orange,
["REPLACE"] = theme.yellow,
["V-REPLACE"] = theme.purple,
["ENTER"] = theme.purple,
["MORE"] = theme.purple,
["SELECT"] = theme.red,
["SHELL"] = theme.teal,
["TERM"] = theme.off_blue,
["NONE"] = theme.dark_gray,
["COMMAND"] = theme.teal,
}
local modes = setmetatable({
["n"] = "NORMAL",
["no"] = "NORMAL",
["v"] = "VISUAL",
["V"] = "V-LINE",
[""] = "V-BLOCK",
["s"] = "SELECT",
["S"] = "S-LINE",
[""] = "S-BLOCK",
["i"] = "INSERT",
["ic"] = "I",
["R"] = "REPLACE",
["Rv"] = "VR",
["c"] = "COMMAND",
["cv"] = "EX",
["ce"] = "X",
["r"] = "P",
["rm"] = "M",
["r?"] = "C",
["!"] = "SH",
["t"] = "TERM",
}, {
__index = function()
return "-"
end,
})
local component = {}
component.empty = {
provider = function()
return ""
end,
hl = function()
return {
bg = "bg",
}
end,
left_sep = "",
right_sep = "",
}
component.display_cwd = {
provider = function()
local result = vim.fn.getcwd()
local home = os.getenv("HOME")
if home and vim.startswith(result, home) then
result = "~" .. result:sub(home:len() + 1)
end
return " " .. result
end,
hl = function()
return {
fg = "off_blue",
bg = "bg",
style = "bold",
}
end,
left_sep = " ",
right_sep = "",
}
component.vim_mode = {
provider = function()
return modes[vim.api.nvim_get_mode().mode]
end,
hl = function()
return {
fg = require("feline.providers.vi_mode").get_mode_color(),
bg = "bg",
style = "bold",
name = "NeovimModeHLColor",
}
end,
left_sep = "block",
right_sep = "block",
}
component.git_branch = {
provider = "git_branch",
hl = {
fg = "light_gray_bright",
bg = "bg",
style = "bold",
},
left_sep = "block",
right_sep = "",
enabled = function()
return vim.api.nvim_win_get_width(0) > 80
end,
}
component.git_add = {
provider = "git_diff_added",
hl = {
fg = "green",
bg = "bg",
},
left_sep = "",
right_sep = "",
}
component.git_delete = {
provider = "git_diff_removed",
hl = {
fg = "red",
bg = "bg",
},
left_sep = "",
right_sep = "",
}
component.git_change = {
provider = "git_diff_changed",
hl = {
fg = "purple",
bg = "bg",
},
left_sep = "",
right_sep = "",
}
component.separator = {
provider = "",
hl = {
fg = "bg",
bg = "bg",
},
}
component.diagnostic_errors = {
provider = "diagnostic_errors",
hl = {
fg = "red",
},
}
component.diagnostic_warnings = {
provider = "diagnostic_warnings",
hl = {
fg = "yellow",
},
}
component.diagnostic_hints = {
provider = "diagnostic_hints",
hl = {
fg = "glacier",
},
}
component.diagnostic_info = {
provider = "diagnostic_info",
}
component.lsp_status = {
provider = function()
if not rawget(vim, "lsp") then
return ""
end
local progress = vim.lsp.util.get_progress_messages()[1]
if vim.o.columns < 120 then
return ""
end
local clients = vim.lsp.get_clients({ bufnr = 0 })
if #clients ~= 0 then
if progress then
local spinners = {
"◜ ",
"◠ ",
"◝ ",
"◞ ",
"◡ ",
"◟ ",
}
local ms = vim.loop.hrtime() / 1000000
local frame = math.floor(ms / 120) % #spinners
local content = string.format("%%<%s", spinners[frame + 1])
return content or ""
else
return "לּ LSP"
end
end
return ""
end,
hl = {},
left_sep = "",
right_sep = "",
}
component.lsp = {
provider = function(msg)
msg = msg or ""
local buf_clients = vim.lsp.get_active_clients({ bufnr = 0 })
if next(buf_clients) == nil then
if type(msg) == "boolean" or #msg == 0 then
return ""
end
return msg
end
local buf_ft = vim.bo.filetype
local buf_client_names = {}
-- add client
for _, client in pairs(buf_clients) do
if client.name ~= "null-ls" then
table.insert(buf_client_names, client.name)
end
end
-- add formatter
local lsp_utils = require("plugins.lsp.utils")
local formatters = lsp_utils.list_formatters(buf_ft)
vim.list_extend(buf_client_names, formatters)
-- add linter
local linters = lsp_utils.list_linters(buf_ft)
vim.list_extend(buf_client_names, linters)
-- add hover
local hovers = lsp_utils.list_hovers(buf_ft)
vim.list_extend(buf_client_names, hovers)
-- add code action
local code_actions = lsp_utils.list_code_actions(buf_ft)
vim.list_extend(buf_client_names, code_actions)
local hash = {}
local client_names = {}
for _, v in ipairs(buf_client_names) do
if not hash[v] then
client_names[#client_names + 1] = v
hash[v] = true
end
end
table.sort(client_names)
return icons.ui.Code .. " " .. table.concat(client_names, ", ") .. " " .. icons.ui.Code .. " "
end,
hl = function()
return {
fg = "green",
bg = "bg",
style = "bold",
}
end,
left_sep = " ",
right_sep = "",
enabled = function()
return vim.api.nvim_win_get_width(0) > 80
end,
}
component.lazy_status = {
provider = function()
local res = require("lazy.status").has_updates()
if res then
return tostring(require("lazy.status").updates())
else
return ""
end
end,
hl = function()
return {
fg = "orange",
bg = "bg",
style = "bold",
}
end,
left_sep = "block",
right_sep = "block",
}
component.file_type = {
provider = {
name = "file_type",
opts = {
filetype_icon = true,
case = "lowercase",
},
},
hl = {
fg = "fg",
bg = "bg",
},
left_sep = "block",
right_sep = "block",
}
component.line_percentage = {
provider = function()
local curr_line = vim.api.nvim_win_get_cursor(0)[1]
local lines = vim.api.nvim_buf_line_count(0)
if curr_line == 1 then
return " "
elseif curr_line == lines then
return " "
else
return string.format("%2d%%%%", math.ceil(curr_line / lines * 99))
end
end,
hl = function()
local position = math.floor(vim.api.nvim_win_get_cursor(0)[1] / vim.api.nvim_buf_line_count(0) * 100)
local fg
local style
if position <= 5 then
fg = "green"
style = "bold"
elseif position >= 95 then
fg = "orange"
style = "bold"
else
fg = "yellow"
style = nil
end
return {
fg = fg,
style = style,
bg = "bg",
}
end,
left_sep = " ",
right_sep = "",
}
component.file_info = {
provider = "file_info",
hl = {
fg = "fg",
bg = "bg",
style = "bold",
},
left_sep = " ",
right_sep = "",
}
component.current_position = {
provider = function()
return fmt(" %3d:%-2d", unpack(vim.api.nvim_win_get_cursor(0)))
end,
hl = {
fg = "fg",
bg = "bg",
},
left_sep = "",
right_sep = "",
}
component.search_count = {
provider = "search_count",
hl = {
fg = "fg",
bg = "bg",
},
left_sep = "",
right_sep = "",
}
component.scroll_bar = {
provider = function()
local opts = { reverse = true }
local scroll_bar_blocks = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }
local curr_line = vim.api.nvim_win_get_cursor(0)[1]
local lines = vim.api.nvim_buf_line_count(0)
if opts.reverse then
return string.rep(scroll_bar_blocks[8 - math.floor(curr_line / lines * 7)], 2)
else
return string.rep(scroll_bar_blocks[math.floor(curr_line / lines * 7) + 1], 2)
end
end,
hl = function()
local position = math.floor(vim.api.nvim_win_get_cursor(0)[1] / vim.api.nvim_buf_line_count(0) * 100)
local fg
local style
if position <= 5 then
fg = "glacier"
style = "bold"
elseif position >= 95 then
fg = "red"
style = "bold"
else
fg = "purple"
style = nil
end
return {
fg = fg,
style = style,
bg = "bg",
}
end,
left_sep = "|",
right_sep = "",
}
local left = {
component.vim_mode,
-- component.file_info,
component.display_cwd,
-- component.file_type,
component.git_add,
component.git_delete,
component.git_change,
}
local right = {
component.separator,
component.diagnostic_errors,
component.diagnostic_warnings,
component.diagnostic_info,
component.diagnostic_hints,
-- component.search_count,
-- component.lsp_status,
-- component.lazy_status,
component.lsp,
component.git_branch,
-- component.current_position,
component.line_percentage,
-- component.scroll_bar
}
local components = {
active = { left, right },
inactive = { { component.empty }, { component.empty } },
}
return {
components = components,
theme = theme,
vim_mode_colors = mode_theme,
force_inactive = {
filetypes = { "^neo%-tree$" },
buftypes = { "^terminal$" },
bufnames = {},
},
}
end,
}
}