summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/statusline.lua
blob: e91ac491310117701928feb4f387cb07ed85e01d (plain)
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
local api = vim.api

Statusline = {
	active = '',
	inactive = '',
}

-- highlight groups
local colors = {
	active        = '%#StatusLine#',
	inactive      = '%#StatuslineNC#',
	mode          = '%#Mode#',
	mode_alt      = '%#ModeAlt#',
	git           = '%#Git#',
	git_alt       = '%#GitAlt#',
	filetype      = '%#Filetype#',
	filetype_alt  = '%#FiletypeAlt#',
	line_col      = '%#LineCol#',
	line_col_alt  = '%#LineColAlt#',
}

Statusline.get_filetype = function()
	local filetype = vim.bo.filetype
	if filetype == '' then
		return ''
	end
	return string.format('%s', filetype):lower()
end

local add_active = function(text)
	Statusline.active = Statusline.active .. text
end

local add_inactive = function(text)
	Statusline.inactive = Statusline.inactive .. text
end

local addl_active = function(func)
	Statusline.active = Statusline.active .. '%{v:lua.' .. func .. '}'
end

local addl_inactive = function(func)
	Statusline.inactive = Statusline.inactive .. '%{v:lua.' .. func .. '}'
end

add_active('[')
addl_active('vim.api.nvim_get_mode().mode')
add_active(']')
add_active(' ')
add_active('%<%f')
add_active(' ')
add_active('%m%r%q')
add_active(' ')
addl_active('Statusline.get_filetype()')
add_active('%=')
addl_active('require("nvim-navic").get_location()')
add_active(' ')
add_active('%l:%c')
add_active(' ')

add_inactive(colors.inactive .. '%F')

local augroup = api.nvim_create_augroup('Statusline', { clear = true})
api.nvim_create_autocmd({"WinEnter", "BufEnter"}, {
	callback = function()
		vim.wo.statusline = Statusline.active
	end,
	group = augroup
})
api.nvim_create_autocmd({"WinLeave", "BufLeave"}, {
	callback = function()
		vim.wo.statusline = Statusline.inactive
	end,
	group = augroup
})

----[[
--  NOTE: I don't use this since the statusline already has
--  so much stuff going on. Feel free to use it!
--  credit: https://github.com/nvim-lua/lsp-status.nvim
--
--  I now use `tabline` to display these errors, go to `_bufferline.lua` if you
--  want to check that out
----]]
-- Statusline.get_lsp_diagnostic = function(self)
--   local result = {}
--   local levels = {
--     errors = 'Error',
--     warnings = 'Warning',
--     info = 'Information',
--     hints = 'Hint'
--   }

--   for k, level in pairs(levels) do
--     result[k] = vim.lsp.diagnostic.get_count(0, level)
--   end

--   if self:is_truncated(120) then
--     return ''
--   else
--     return string.format(
--       "| :%s :%s :%s :%s ",
--       result['errors'] or 0, result['warnings'] or 0,
--       result['info'] or 0, result['hints'] or 0
--     )
--   end
-- end
--
--local get_git_status = function()
	---- use fallback because it doesn't set this variable on the initial `BufEnter`
	--local signs = vim.b.gitsigns_status_dict or {head = '', added = 0, changed = 0, removed = 0}
	--local is_head_empty = signs.head ~= ''
--
	--if is_truncated(trunc_width.git_status) then
		--return is_head_empty and string.format('  %s ', signs.head or '') or ''
	--end
--
	--return is_head_empty and string.format(
	--' +%s ~%s -%s |  %s ',
	--signs.added, signs.changed, signs.removed, signs.head
	--) or ''
--end