Skip to content

Commit a75aed0

Browse files
committed
refactor(lualine): Rewrite sections, fix faulty annotations.
Signed-off-by: Guennadi Maximov C <[email protected]>
1 parent 437847f commit a75aed0

File tree

2 files changed

+120
-126
lines changed

2 files changed

+120
-126
lines changed

lua/plugin/lualine/presets.lua

+112-118
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
---@diagnostic disable:unused-function
2-
---@diagnostic disable:unused-local
3-
41
local user = require('user_api')
52
local Check = user.check
63
local types = user.types.lualine
@@ -12,169 +9,166 @@ local floor = math.floor
129
local M = {}
1310

1411
---@diagnostic disable-next-line:missing-fields
15-
M.components = {
16-
buffers = {
17-
'buffers',
18-
19-
filetype_names = {
20-
TelescopePrompt = 'Telescope',
21-
dashboard = 'Dashboard',
22-
packer = 'Packer',
23-
lazy = 'Lazy',
24-
fzf = 'FZF',
25-
alpha = 'Alpha',
26-
NvimTree = 'Nvim Tree',
27-
},
28-
29-
symbols = {
30-
modified = '', -- Text to show when the buffer is modified
31-
alternate_file = '#', -- Text to show to identify the alternate file
32-
directory = '', -- Text to show when the buffer is a directory
33-
},
34-
35-
buffers_color = {
36-
active = 'lualine_a_normal',
37-
inactive = 'lualine_a_inactive',
38-
},
12+
M.components = {}
13+
M.components.buffers = {
14+
'buffers',
3915

40-
max_length = floor(vim.opt.columns:get() * 2 / 3),
16+
filetype_names = {
17+
TelescopePrompt = 'Telescope',
18+
dashboard = 'Dashboard',
19+
packer = 'Packer',
20+
lazy = 'Lazy',
21+
fzf = 'FZF',
22+
alpha = 'Alpha',
23+
NvimTree = 'Nvim Tree',
4124
},
4225

43-
diff = {
44-
'diff',
45-
colored = true,
46-
diff_color = {
47-
added = 'LuaLineDiffAdd',
48-
modified = 'LuaLineDiffChange',
49-
removed = 'LuaLineDiffDelete',
50-
},
51-
52-
symbols = {
53-
added = '+',
54-
modified = '~',
55-
removed = '-',
56-
},
26+
symbols = {
27+
modified = '', -- Text to show when the buffer is modified
28+
alternate_file = '#', -- Text to identify the alternate file
29+
directory = '', -- Text to show when the buffer is a directory
5730
},
5831

59-
encoding = { 'encoding' },
60-
hostname = { 'hostname' },
61-
location = { 'location' },
62-
selectioncount = { 'selectioncount' },
32+
buffers_color = {
33+
active = 'lualine_a_normal',
34+
inactive = 'lualine_a_inactive',
35+
},
6336

64-
filename = {
65-
'filename',
37+
max_length = floor(vim.opt.columns:get() / 4),
38+
}
6639

67-
file_status = true,
68-
newfile_status = false,
69-
path = 4,
40+
M.components.diff = {
41+
'diff',
42+
colored = true,
43+
diff_color = {
44+
added = 'LuaLineDiffAdd',
45+
modified = 'LuaLineDiffChange',
46+
removed = 'LuaLineDiffDelete',
7047
},
7148

72-
filetype = {
73-
'filetype',
74-
colored = true,
75-
icon_only = false,
76-
icon = { align = 'right' },
49+
symbols = {
50+
added = '+',
51+
modified = '~',
52+
removed = '-',
7753
},
54+
}
7855

79-
branch = { 'branch' },
56+
M.components.branch = { 'branch' }
57+
M.components.encoding = { 'encoding' }
58+
M.components.hostname = { 'hostname' }
59+
M.components.location = { 'location' }
60+
M.components.selectioncount = { 'selectioncount' }
61+
M.components.filesize = { 'filesize' }
8062

81-
fileformat = {
82-
'fileformat',
63+
M.components.filename = {
64+
'filename',
8365

84-
symbols = {
85-
unix = '', -- e712
86-
dos = '', -- e70f
87-
mac = '', -- e711
88-
},
89-
},
66+
file_status = true,
67+
newfile_status = false,
68+
path = 4,
69+
}
9070

91-
searchcount = {
92-
maxcount = 999,
93-
timeout = 500,
94-
},
71+
M.components.filetype = {
72+
'filetype',
73+
colored = true,
74+
icon_only = false,
75+
icon = { align = 'right' },
76+
}
77+
78+
M.components.fileformat = {
79+
'fileformat',
9580

96-
filesize = {
97-
'filesize',
81+
symbols = {
82+
unix = '', -- e712
83+
dos = '', -- e70f
84+
mac = '', -- e711
9885
},
86+
}
9987

100-
tabs = {
101-
'tabs',
88+
M.components.searchcount = {
89+
'searchcount',
90+
maxcount = 999,
91+
timeout = 500,
92+
}
10293

103-
tab_max_length = floor(vim.opt.columns:get() / 3),
94+
M.components.tabs = {
95+
'tabs',
10496

105-
mode = 2,
106-
path = 1,
107-
},
97+
tab_max_length = floor(vim.opt.columns:get() / 3),
10898

99+
mode = 2,
100+
path = 1,
109101
tabs_color = {
110102
active = 'lualine_b_normal',
111103
inactive = 'lualine_b_inactive',
112104
},
105+
}
113106

114-
windows = {
115-
'windows',
116-
117-
max_length = floor(vim.opt.columns:get() * 2 / 3),
107+
M.components.windows = {
108+
'windows',
118109

119-
disabled_buftypes = {
120-
'quickfix',
121-
'prompt',
122-
},
110+
max_length = floor(vim.opt.columns:get() / 5),
123111

124-
windows_color = {
125-
active = 'lualine_z_normal',
126-
inactive = 'lualine_z_inactive',
127-
},
112+
disabled_buftypes = {
113+
'quickfix',
114+
'prompt',
128115
},
129116

130-
diagnostics = {
131-
'diagnostics',
132-
133-
sources = {
134-
'nvim_workspace_diagnostic',
135-
},
117+
windows_color = {
118+
active = 'lualine_z_normal',
119+
inactive = 'lualine_z_inactive',
120+
},
121+
}
136122

137-
sections = { 'error', 'warn' },
123+
M.components.diagnostics = {
124+
'diagnostics',
138125

139-
diagnostics_color = {
140-
error = 'DiagnosticError',
141-
warn = 'DiagnosticWarn',
142-
info = 'DiagnosticInfo',
143-
hint = 'DiagnosticHint',
144-
},
126+
sources = {
127+
'nvim_workspace_diagnostic',
128+
},
145129

146-
symbols = {
147-
error = '󰅚 ',
148-
hint = '󰌶 ',
149-
info = '',
150-
warn = '󰀪 ',
151-
},
130+
sections = { 'error', 'warn', 'info', 'hint' },
152131

153-
colored = true,
154-
update_in_insert = false,
155-
always_visible = true,
132+
diagnostics_color = {
133+
error = 'DiagnosticError',
134+
warn = 'DiagnosticWarn',
135+
info = 'DiagnosticInfo',
136+
hint = 'DiagnosticHint',
156137
},
157138

158-
datetime = {
159-
'datetime',
160-
style = 'uk',
139+
symbols = {
140+
error = '󰅚 ',
141+
hint = '󰌶 ',
142+
info = '',
143+
warn = '󰀪 ',
161144
},
162145

163-
mode = {
164-
'mode',
165-
fmt = function(str) return str:sub(1, 1) end,
166-
},
146+
colored = true,
147+
update_in_insert = false,
148+
always_visible = true,
149+
}
150+
151+
M.components.datetime = {
152+
'datetime',
153+
style = 'uk',
154+
}
155+
156+
M.components.mode = {
157+
'mode',
158+
fmt = function(str) return str:sub(1, 1) end,
167159
}
168160

169161
M.default = {
170162
lualine_a = {
171163
M.components.mode,
172164
},
173165
lualine_b = {
166+
M.components.branch,
174167
M.components.filename,
175168
},
176169
lualine_c = {
177170
M.components.diagnostics,
171+
M.components.diff,
178172
},
179173
lualine_x = {
180174
M.components.encoding,

lua/user_api/types/lualine.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@
7575
---@field style? 'default'|'us'|'uk'|'iso'|string
7676

7777
---@class DiagnosticsInteger
78-
---@field error? integer
79-
---@field warn? integer
80-
---@field info? integer
81-
---@field hint? integer
78+
---@field error? string|integer
79+
---@field warn? string|integer
80+
---@field info? string|integer
81+
---@field hint? string|integer
8282

8383
---@class DiagnosticsColor: DiagnosticsInteger
84-
---@field error? integer
85-
---@field warn? integer
86-
---@field info? integer
87-
---@field hint? integer
84+
---@field error? string|integer
85+
---@field warn? string|integer
86+
---@field info? string|integer
87+
---@field hint? string|integer
8888

8989
---@class LuaLine.Components.Diagnostics
9090
---@field [1] 'diagnostics'

0 commit comments

Comments
 (0)