-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalaxyline.lua
371 lines (352 loc) · 10.1 KB
/
galaxyline.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
local status_ok, gl = pcall(require, 'galaxyline')
if not status_ok then
print("Couldn't load 'galaxyline'")
return
end
local colors = require('galaxyline.theme').default
local condition = require('galaxyline.condition')
gl.short_line_list = { 'NvimTree', 'Outline', 'Trouble', 'qf', }
colors.green = "#118822"
colors.blue = "#4466aa"
colors.red = "#aa4422"
colors.grayblue = "#283034"
colors.gray = "#767676"
colors.none = function()
local sl = vim.api.nvim_get_hl_by_name('StatusLine', true)
local color = sl.reverse and sl.foreground or sl.background
return color and string.format("#%x", color) or "NONE"
end
local separators = {
right = ' ',
left = '',
right_thin = ' ',
left_thin = ' ',
}
local function buffer_not_empty()
return #vim.fn.expand('%:t') > 0
end
---@param width integer
local function window_wider_than(width)
return vim.fn.winwidth(0) >= width
end
---@param width integer
local function can_show_git_at(width)
return function()
return buffer_not_empty() and window_wider_than(width) and condition.check_git_workspace()
end
end
local sections = { left = 0, mid = 0, right = 0, short_line_left = 0, short_line_right = 0, }
local function section(pos, tbl)
sections[pos] = sections[pos] + 1
gl.section[pos][sections[pos]] = tbl
end
--- Defines the highlight colors for a section of GalaxyLine
---@class VimMode
---@field text string?
---@field fg string
---@field bg string
local modes = {
n = { text = "NORMAL", fg = colors.bg, bg = colors.yellow, }, ---@type VimMode
i = { text = "INSERT", bg = colors.green, }, ---@type VimMode
v = { text = "VISUAL", bg = colors.blue, }, ---@type VimMode
V = { text = "VISUAL-LINE", bg = colors.blue, }, ---@type VimMode
[''] = { text = "VISUAL-BLOCK", bg = colors.blue, }, ---@type VimMode
S = { text = "SELECT-LINE", bg = colors.red, }, ---@type VimMode
[''] = { text = "SELECT-BLOCK", bg = colors.red, }, ---@type VimMode
c = { text = "COMMAND", fg = colors.bg, bg = colors.blue, }, ---@type VimMode
R = { text = "REPLACE", bg = colors.red, }, ---@type VimMode
r = { text = "PRESS ENTER", fg = colors.bg, bg = colors.green, }, ---@type VimMode
t = { text = "TERMINAL", fg = colors.bg, bg = colors.red, }, ---@type VimMode
default = { text = nil, fg = colors.bg, bg = colors.red, }, ---@type VimMode
}
for m, _ in pairs(modes) do
modes[m] = vim.tbl_extend("keep", modes[m], { fg = colors.fg, bg = colors.bg })
end
local function ViModeLeftSection()
---@type VimMode
local vimode = modes.n
section('left', {
Vim = {
provider = function() return ' ' end,
highlight = { colors.green, colors.bg },
}
})
section('left', {
VimSeparator = {
provider = function()
vimode = modes[vim.fn.mode()] or modes.default
vim.api.nvim_command('hi GalaxyVimSeparator guifg=' .. colors.bg .. ' guibg=' .. vimode.bg)
return separators.right
end,
}
})
section('left', {
ViMode = {
provider = function()
vim.api.nvim_command('hi GalaxyViMode gui=BOLD guifg=' .. vimode.fg .. ' guibg=' .. vimode.bg)
return vimode.text or vim.fn.mode(1)
end,
}
})
section('left', {
ViModeSeparator = {
provider = function()
local bgcolor = (buffer_not_empty() and condition.check_git_workspace()) and colors.bg or colors.none()
vim.api.nvim_command('hi GalaxyViModeSeparator guifg=' .. vimode.bg .. ' guibg=' .. bgcolor)
return separators.right
end,
}
})
end
ViModeLeftSection()
section('left', {
GitBranch = {
condition = can_show_git_at(60),
provider = function()
return require('galaxyline.provider_vcs').get_git_branch()
end,
icon = ' ',
highlight = { colors.orange, colors.bg },
separator = separators.right,
separator_highlight = { colors.bg, colors.none },
}
})
local function GitChanges()
local vcs = require('galaxyline.provider_vcs')
section('left', {
GitDiffs = {
condition = can_show_git_at(90),
provider = function()
local diffs = vcs.diff_modified()
return (diffs and '~'..diffs or '')
end,
highlight = { colors.blue, colors.none },
}
})
section('left', {
GitAdds = {
condition = can_show_git_at(90),
provider = function()
local adds = vcs.diff_add()
return (adds and '+'..adds or '')
end,
highlight = { colors.green, colors.none },
}
})
section('left', {
GitRems = {
condition = can_show_git_at(90),
provider = function()
local rems = vcs.diff_remove()
return (rems and '-'..rems or '')
end,
highlight = { colors.red, colors.none },
}
})
end
GitChanges()
section('mid', {
FileInformationPre = {
condition = buffer_not_empty,
provider = function() return separators.left end,
highlight = { colors.grayblue, colors.none },
}
})
section('mid', {
FileIcon = {
condition = buffer_not_empty,
provider = 'FileIcon',
highlight = { require('galaxyline.provider_fileinfo').get_file_icon_color, colors.grayblue },
}
})
section('mid', {
FileName = {
condition = buffer_not_empty,
provider = function()
return vim.fn.expand('%:.') .. ' '
end,
highlight = { colors.fg, colors.grayblue, },
}
})
section('mid', {
FileModified = {
condition = buffer_not_empty,
provider = function() return vim.bo.modified and 'פֿ ' or '' end,
highlight = { colors.yellow, colors.grayblue },
}
})
section('mid', {
FileReadOnly = {
condition = function() return buffer_not_empty() and vim.bo.readonly end,
provider = function() return '' end,
separator = ' ',
highlight = { colors.red, colors.grayblue },
separator_highlight = { colors.red, colors.grayblue },
}
})
local function LspMidSection()
local lsp_active = false
section('mid', {
LspServerSeparator = {
condition = function() return window_wider_than(75) and buffer_not_empty() end,
provider = function()
lsp_active = next(vim.lsp.buf_get_clients()) ~= nil
return lsp_active and separators.right_thin or ''
end,
highlight = { colors.none, colors.grayblue, 'bold' },
}
})
section('mid', {
LspServerName = {
condition = function() return window_wider_than(75) and buffer_not_empty() end,
provider = function()
return lsp_active and require('galaxyline.provider_lsp').get_lsp_client() or ''
end,
icon = ' ',
highlight = { colors.violet, colors.grayblue },
}
})
end
LspMidSection()
section('mid', {
FileInformationPost = {
condition = buffer_not_empty,
provider = function() return separators.right end,
highlight = { colors.grayblue, colors.none },
}
})
local function Diagnostics()
local diagnostics = {}
section('mid', {
DiagnosticErrors = {
condition = function() return window_wider_than(60) and buffer_not_empty() end,
provider = function()
diagnostics = vim.diagnostic.get(0)
local errors = vim.tbl_filter(function(d)
return d.severity == vim.diagnostic.severity.ERROR
end, diagnostics)
if #errors > 0 then
return ' ' .. #errors .. ' '
end
return ''
end,
highlight = { colors.red, colors.none, },
}
})
section('mid', {
DiagnosticWarnings = {
condition = function() return window_wider_than(60) and buffer_not_empty() end,
provider = function()
local warnings = vim.tbl_filter(function(d)
return d.severity == vim.diagnostic.severity.WARN
end, diagnostics)
if #warnings > 0 then
return ' ' .. #warnings .. ' '
end
return ''
end,
highlight = { colors.orange, colors.none, },
}
})
section('mid', {
DiagnosticInfo = {
condition = function() return window_wider_than(60) and buffer_not_empty() end,
provider = function()
local info = vim.tbl_filter(function(d)
return d.severity == vim.diagnostic.severity.INFO
end, diagnostics)
if #info > 0 then
return ' ' .. #info .. ' '
end
return ''
end,
highlight = { colors.violet, colors.none, },
}
})
section('mid', {
DiagnosticHints = {
condition = function() return window_wider_than(60) and buffer_not_empty() end,
provider = function()
local hints = vim.tbl_filter(function(d)
return d.severity == vim.diagnostic.severity.HINT
end, diagnostics)
if #hints > 0 then
return 'ﯧ ' .. #hints .. ' '
end
return ''
end,
highlight = { colors.gray, colors.none, },
}
})
end
Diagnostics()
section('right', {
Indentation = {
condition = function()
return buffer_not_empty() and vim.bo.buftype ~= 'terminal'
end,
provider = function()
return (vim.bo.expandtab and ('·'..vim.bo.shiftwidth) or 'ff') .. ' '
end,
highlight = { colors.gray, colors.none, },
}
})
section('right', {
FileFormat = {
condition = buffer_not_empty,
provider = function()
return ({
unix = ' ',
dos = ' ',
})[vim.bo.fileformat]
end,
highlight = { colors.fg, colors.bg, },
separator = separators.left,
separator_highlight = { colors.bg, colors.none },
}
})
section('right', {
FileTypeName = {
condition = function()
return buffer_not_empty() and vim.bo.buftype ~= 'terminal'
end,
provider = function() return vim.bo.filetype end,
highlight = { colors.fg, colors.bg, 'italic' },
separator = separators.left_thin,
separator_highlight = { colors.none, colors.bg, 'bold' },
}
})
section('right', {
FileSize = {
condition = function()
return buffer_not_empty() and vim.bo.buftype ~= 'terminal' and window_wider_than(60)
end,
provider = 'FileSize',
highlight = { colors.fg, colors.bg, },
separator = ' ' .. separators.left_thin,
separator_highlight = { colors.none, colors.bg, 'bold' },
}
})
section('right', {
CurPos = {
provider = function()
return " " .. vim.fn.line('.') .. ":" .. vim.fn.col('.')
end,
highlight = { colors.fg, colors.bg, 'bold' },
separator = separators.left_thin,
separator_highlight = { colors.fg, colors.bg },
}
})
local function shortlines()
section("short_line_left", {
ShortBuffer = {
provider = function()
return vim.bo.buftype == 'nofile' and vim.bo.filetype or vim.fn.expand("%:.:p")
end,
highlight = { colors.none, colors.gray },
separator = separators.right,
separator_highlight = { colors.gray, colors.bg },
}
})
end
shortlines()