-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
lualine.lua
374 lines (315 loc) · 9.76 KB
/
lualine.lua
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
local config = require('one.config').config
local M = {
'nvim-lualine/lualine.nvim',
desc = 'lualine.nvim',
config = function()
require('lualine').setup(config.statusline.lualine)
end,
}
local printf = string.format
---@return string current mode name
local function getMode()
local mode_code = vim.api.nvim_get_mode().mode
return config.statusline.modeMap[mode_code] or mode_code
end
local function mixLine()
local space_pat = [[\v^ +]]
local tab_pat = [[\v^\t+]]
local space_indent = vim.fn.search(space_pat, 'nwc')
local tab_indent = vim.fn.search(tab_pat, 'nwc')
local mixed = (space_indent > 0 and tab_indent > 0)
local mixed_same_line
if not mixed then
mixed_same_line = vim.fn.search([[\v^(\t+ | +\t)]], 'nwc')
mixed = mixed_same_line > 0
end
if not mixed then return '' end
if mixed_same_line ~= nil and mixed_same_line > 0 then return 'MIX:' .. mixed_same_line end
local space_indent_cnt = vim.fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total
local tab_indent_cnt = vim.fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total
if space_indent_cnt > tab_indent_cnt then
return 'MIX:' .. tab_indent
else
return 'MIX:' .. space_indent
end
end
local function paste()
if vim.o.paste then
return config.statusline.pasteSymbol
else
return ''
end
end
local function bufferNumber()
return 'buf:' .. vim.api.nvim_get_current_buf()
end
local function location()
local row, col = table.unpack(vim.api.nvim_win_get_cursor(0))
local total = vim.api.nvim_buf_line_count(0)
return printf('%s/%s %s', row, total, col)
end
local function spaces()
return printf('ts:%s sw:%s', vim.o.tabstop, vim.o.shiftwidth)
end
local function my_sections(funcs)
return function()
local str = ''
for _, func in pairs(funcs) do str = str .. ' ' .. func() end
return str
end
end
local function theme(colors)
local black = colors.black
local white = colors.white
local green = colors.green
local grey = colors.grey
local sec_c_bg = colors.sec_c_bg
return {
normal = {
a = { fg = black, bg = green, gui = 'bold' },
b = { fg = white, bg = grey },
c = { fg = colors.sec_c_fg, bg = sec_c_bg },
x = { fg = colors.sec_c_fg, bg = colors.sec_x_bg },
y = { fg = white, bg = colors.sec_y_bg },
z = { fg = black, bg = green },
},
insert = { a = { fg = black, bg = colors.blue, gui = 'bold' } },
visual = { a = { fg = black, bg = colors.orange, gui = 'bold' } },
replace = { a = { fg = black, bg = colors.purple, gui = 'bold' } },
command = { a = { fg = black, bg = colors.yellow, gui = 'bold' } },
inactive = {
a = { fg = white, bg = grey, gui = 'bold' },
b = { fg = white, bg = colors.sec_y_bg },
c = { fg = white, bg = black },
},
}
end
local function setNoice(lualineConfig, c)
local has_noice, noice = pcall(require, 'noice')
if has_noice then
local noiceStatus = noice.api.status
table.insert(lualineConfig.winbar.lualine_x, {
function()
local message = require('noice.message.manager').get({ --
event = 'msg_showmode',
}, { count = 1, sort = true })[1]
local str = vim.trim(message:content()):gsub('%%', '%%%%')
if str:find('@') then
return str
else
return ''
end
end,
cond = noiceStatus.mode.has,
color = { fg = '#ff9e64' },
})
table.insert(lualineConfig.winbar.lualine_x, {
function()
local message = require('noice.message.manager').get({ --
event = 'msg_show',
kind = 'search_count',
}, { count = 1, sort = true })[1]
return vim.trim(message:content()):gsub('%%', '%%%%'):gsub('%s*%[%d+/%d+%]$', '')
end,
icon = '',
cond = noiceStatus.search.has,
color = { fg = c.match.fg },
})
end
end
M.defaultConfig = function()
local c = config.colors
local colors = vim.tbl_extend('keep', vim.tbl_get(config, 'statusline', 'colors') or {}, {
red = c.red,
black = c.black,
white = '#d9d7ce',
grey = '#282b2e',
green = '#bbe67e',
blue = '#689afd',
orange = '#D75F00',
purple = '#765ADA',
yellow = '#C7B000',
cyan = '#9ac3de',
sec_y_bg = '#272d38',
sec_c_fg = '#607080',
sec_c_bg = '#12151a',
sec_x_bg = '#121A22',
})
local symbolMap = config.symbolMap
local diagnosticBG = '#0D203A'
local diagnostics = {
'diagnostics',
-- Table of diagnostic sources, available sources are:
-- 'nvim_lsp', 'nvim_diagnostic', 'nvim_workspace_diagnostic', 'coc', 'ale', 'vim_lsp'.
-- or a function that returns a table as such:
-- { error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt }
sources = { 'nvim_diagnostic' },
-- Displays diagnostics for the defined severity types
sections = { 'error', 'warn', 'info', 'hint' },
diagnostics_color = {
-- Same values as the general color option can be used here.
error = { fg = colors.red, bg = diagnosticBG },
warn = { fg = colors.yellow, bg = diagnosticBG },
info = { fg = colors.blue, bg = diagnosticBG },
hint = { fg = colors.cyan, bg = diagnosticBG },
},
symbols = {
error = symbolMap.ERROR .. ' ',
warn = symbolMap.WARN .. ' ',
info = symbolMap.INFO .. ' ',
hint = symbolMap.HINT .. ' ',
},
colored = true, -- Displays diagnostics status in color if set to true.
update_in_insert = false, -- Update diagnostics in insert mode.
always_visible = false, -- Show diagnostics even if there are none.
}
local filename = {
'filename',
file_status = true, -- Displays file status (readonly status, modified status)
newfile_status = true, -- Display new file status (new file means no write after created)
path = 1, -- 0: Just the filename
-- 1: Relative path
-- 2: Absolute path
-- 3: Absolute path, with tilde as the home directory
shorting_target = 40, -- Shortens path to leave 40 spaces in the window
-- for other components. (terrible name, any suggestions?)
symbols = {
modified = '[*]', -- Text to show when the file is modified.
readonly = ' ' .. symbolMap.LOCK, -- Text to show when the file is non-modifiable or readonly.
unnamed = '[No Name]', -- Text to show for unnamed buffers.
newfile = '[New]', -- Text to show for new created file before first writting
},
}
local aerial = {
'aerial',
sep = ' > ', -- The separator to be used to separate symbols in status line.
-- The number of symbols to render top-down. In order to render only 'N' last
-- symbols, negative numbers may be supplied. For instance, 'depth = -1' can
-- be used in order to render only current symbol.
depth = nil,
-- When 'dense' mode is on, icons are not rendered near their symbols. Only
-- a single icon that represents the kind of current symbol is rendered at
-- the beginning of status line.
dense = false,
dense_sep = '.', -- The separator to be used to separate symbols in dense mode.
colored = true, -- Color the symbol icons.
color = { fg = colors.cyan, bg = '#0A1921', gui = 'bold' },
}
local progress = require('lualine.components.progress')
local lualineConfig = {
options = {
icons_enabled = true,
theme = theme(colors),
-- component_separators = { left = '', right = '' },
component_separators = { left = '│', right = '│' },
section_separators = { left = '', right = '' },
disabled_filetypes = {
statusline = { 'alpha' },
winbar = { 'alpha', 'aerial', 'neo-tree', 'nerdtree', 'NvimTree' },
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = true,
-- how often lualine should refreash it's contents (in ms)
refresh = { statusline = 5000, tabline = 0, winbar = 500 },
},
sections = {
lualine_a = { getMode },
lualine_b = { { 'branch', icon = symbolMap.BRANCH } },
lualine_c = { filename },
lualine_x = { my_sections({ progress, location, spaces, bufferNumber }), 'filesize' },
lualine_y = { 'filetype' },
lualine_z = { 'encoding', 'fileformat', mixLine, paste },
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {},
lualine_x = {},
lualine_y = {},
lualine_z = {},
},
winbar = {
lualine_a = { diagnostics },
lualine_b = {},
lualine_c = { aerial },
lualine_x = {
{ -- Let winbar always visible
function()
return ' '
end,
padding = 0,
},
},
lualine_y = {},
lualine_z = {},
},
tabline = {},
extensions = {},
}
lualineConfig.inactive_winbar = lualineConfig.winbar
local has_navic, navic = pcall(require, 'nvim-navic')
if has_navic then
table.insert(lualineConfig.winbar.lualine_c, {
navic.get_location,
cond = navic.is_available,
color = { fg = colors.cyan, bg = '#0A1921', gui = 'underline' },
})
end
local has_auto_session, autoSessionLibrary = pcall(require, 'auto-session-library')
if has_auto_session then
table.insert(lualineConfig.sections.lualine_x, function()
return printf('#%s', autoSessionLibrary.current_session_name())
end)
end
setNoice(lualineConfig, c)
return {
'statusline',
{
colors = colors,
pasteSymbol = 'Ƥ',
modeMap = {
['n'] = 'N', -- 'NORMAL'
['no'] = 'O-PENDING',
['nov'] = 'O-PENDING',
['noV'] = 'O-PENDING',
['no\22'] = 'O-PENDING',
['niI'] = 'NORMAL',
['niR'] = 'NORMAL',
['niV'] = 'NORMAL',
['nt'] = 'NORMAL',
['ntT'] = 'NORMAL',
['v'] = 'V', -- 'VISUAL'
['vs'] = 'VISUAL',
['V'] = 'V-LINE',
['Vs'] = 'V-LINE',
['\22'] = 'V-BLOCK',
['\22s'] = 'V-BLOCK',
['^V'] = 'V-BLOCK',
['multi'] = 'Multi',
['s'] = 'SELECT',
['S'] = 'S-LINE',
['\19'] = 'S-BLOCK',
['i'] = 'I', -- 'INSERT',
['ic'] = 'INSERT',
['ix'] = 'INSERT',
['R'] = 'R', -- 'REPLACE'
['Rc'] = 'REPLACE',
['Rx'] = 'REPLACE',
['Rv'] = 'V-REPLACE',
['Rvc'] = 'V-REPLACE',
['Rvx'] = 'V-REPLACE',
['c'] = 'C',
['cv'] = 'EX',
['ce'] = 'EX',
['r'] = 'REPLACE',
['rm'] = 'MORE',
['r?'] = 'CONFIRM',
['!'] = 'SHELL',
['t'] = 'TERMINAL',
},
lualine = lualineConfig,
},
}
end
return M