diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-03-19 17:00:55 -0300 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-03-19 17:00:55 -0300 |
commit | b876e4afcab3d01f9207f9f4794828fd8b091d9d (patch) | |
tree | 961668cb627df81fc8b75e1041c8d971700d7256 /.config/nvim/lua/statusline.lua | |
parent | 0749b67fbf4bcffda1ad75d9d343dfc753faf706 (diff) |
nvim,zzszh,gpg,i3
Diffstat (limited to '.config/nvim/lua/statusline.lua')
-rw-r--r-- | .config/nvim/lua/statusline.lua | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/.config/nvim/lua/statusline.lua b/.config/nvim/lua/statusline.lua new file mode 100644 index 0000000..b7b6ed9 --- /dev/null +++ b/.config/nvim/lua/statusline.lua @@ -0,0 +1,202 @@ +local fn = vim.fn +local api = vim.api + +-- possible values are 'arrow' | 'rounded' | 'blank' +local active_sep = 'blank' + +-- change them if you want to different separator +local separators = { + arrow = { '', '' }, + rounded = { '', '' }, + blank = { '', '' }, +} + +-- 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#', +} + +local trunc_width = setmetatable({ + mode = 80, + git_status = 90, + filename = 140, + line_col = 60, +}, { + __index = function() + return 80 + end +}) + +local is_truncated = function(_, width) + local current_width = api.nvim_win_get_width(0) + return current_width < width +end + +--local modes = setmetatable({ + --['n'] = {'Normal', 'N'}; + --['no'] = {'N·Pending', 'N·P'} ; + --['v'] = {'Visual', 'V' }; + --['V'] = {'V·Line', 'V·L' }; + --[''] = {'V·Block', 'V·B'}; -- this is not ^V, but it's , they're different + --['s'] = {'Select', 'S'}; + --['S'] = {'S·Line', 'S·L'}; + --[''] = {'S·Block', 'S·B'}; -- same with this one, it's not ^S but it's + --['i'] = {'Insert', 'I'}; + --['ic'] = {'Insert', 'I'}; + --['R'] = {'Replace', 'R'}; + --['Rv'] = {'V·Replace', 'V·R'}; + --['c'] = {'Command', 'C'}; + --['cv'] = {'Vim·Ex ', 'V·E'}; + --['ce'] = {'Ex ', 'E'}; + --['r'] = {'Prompt ', 'P'}; + --['rm'] = {'More ', 'M'}; + --['r?'] = {'Confirm ', 'C'}; + --['!'] = {'Shell ', 'S'}; + --['t'] = {'Terminal ', 'T'}; +--}, { + --__index = function() + --return {'Unknown', 'U'} -- handle edge cases + --end +--}) + +local get_current_mode = function() + return string.format('[%s]', api.nvim_get_mode().mode ) +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 + +local get_filename = function() + --if is_truncated(trunc_width.filename) then return "%<%f" end + return "%<%F" +end + +local get_filetype = function() + local filetype = vim.bo.filetype + if filetype == '' then + return '' + end + return string.format('%s', filetype):lower() +end + +local get_line_col = function() + return '%l:%c' +end + +Statusline = {} + +Statusline.active = function() + local navic = require('nvim-navic') + + --local mode = colors.mode .. self:get_current_mode() + --local mode_alt = colors.mode_alt .. self.separators[active_sep][1] + --local git = colors.git .. self:get_git_status() + --local git_alt = colors.git_alt .. self.separators[active_sep][1] + --local filename = colors.inactive .. self:get_filename() .. colors.git_alt + --local location = "" + --if navic.is_available() then + --location = navic.get_location() + --end + --local filetype_alt = colors.filetype_alt .. self.separators[active_sep][2] + --local filetype = colors.filetype .. self:get_filetype() + --local line_col = colors.line_col .. self:get_line_col() + --local line_col_alt = colors.line_col_alt .. self.separators[active_sep][2] + + local mode = get_current_mode() + --local git = get_git_status() + local filename = get_filename() .. colors.git_alt + local location = "" + if navic.is_available() then + location = navic.get_location() + end + local filetype = get_filetype() + local line_col = get_line_col() + + return table.concat({ + mode, " ", filename, " ", "%m%r%q", " ", filetype, + "%=", + location, " ", line_col, " " + }) +end + +Statusline.inactive = function() + return colors.inactive .. '%F' +end + +Statusline.set_explorer = function() + local title = colors.mode .. ' ' + local title_alt = colors.mode_alt .. Statusline.separators[active_sep][2] + + return table.concat({ colors.active, title, title_alt }) +end + +--Statusline = setmetatable(M, { + --__call = function(statusline, mode) + --if mode == "active" then return statusline:set_active() end + --if mode == "inactive" then return statusline:set_inactive() end + --if mode == "explorer" then return statusline:set_explorer() end + --end +--}) + +local augroup = api.nvim_create_augroup('Statusline', { clear = true}) +api.nvim_create_autocmd({"WinEnter", "BufEnter"}, { + command = "setlocal statusline=%!v:lua.Statusline.active()", + group = augroup +}) +api.nvim_create_autocmd({"WinLeave", "BufLeave"}, { + command = "setlocal statusline=%!v:lua.Statusline.inactive()", + 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 |