diff options
| Commit | 34a94913f37d9db03489f4a4a86ef63e2fa07c14 (patch) | |
|---|---|---|
| Author | 2024-03-24 16:24:33 +0200 | |
| Committer | 2024-03-24 16:24:33 +0200 | |
| Files | ff8826e1792691799326cc019f18ad9744a4b0ac /lua | |
| anderson-34a94913f37d9db03489f4a4a86ef63e2fa07c14.tar anderson-34a94913f37d9db03489f4a4a86ef63e2fa07c14.tar.gz anderson-34a94913f37d9db03489f4a4a86ef63e2fa07c14.zip | ||
| Parent | 9e5ade95389861c417974c43b1615deb90855436 (diff) | |
[p/heirline] Added statusline config
2 files changed, 164 insertions, 0 deletions
| -rw-r--r-- | lua/plugins.lua | 5 | ||||
| -rw-r--r-- | lua/plugins/heirline.lua | 159 |
diff --git a/lua/plugins.lua b/lua/plugins.lua index c57467b..00db4ce 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -4,6 +4,8 @@ vim.call('plug#begin') Plug("morhetz/gruvbox") -- Color theme Plug("nvim-treesitter/nvim-treesitter") Plug("neovim/nvim-lspconfig") +Plug("nvim-tree/nvim-web-devicons") +Plug("rebelot/heirline.nvim") vim.call('plug#end') @@ -22,3 +24,6 @@ require("nvim-treesitter.configs").setup({ incremental_selection = { enable = true }, textobjects = { enable = true }, }) + +--[==[ Heirline ]==]-- +require("plugins.heirline") diff --git a/lua/plugins/heirline.lua b/lua/plugins/heirline.lua new file mode 100644 index 0000000..126066a --- /dev/null +++ b/lua/plugins/heirline.lua @@ -0,0 +1,159 @@ +local utils = require("heirline.utils") +local conditions = require("heirline.conditions") + +--[=[ Helpers ]=]-- + +function inverseColors(highlight) + if highlight == nil then return nil end + + if type(highlight) == "string" then + highlight = utils.get_highlight(highlight) + end + + highlight.cterm = { reverse = true } + return highlight +end + +local delimiters = { + FilledCircle = { "", "" }, + Circle = { "", "" }, +} +local StatusLineColor = utils.get_highlight("StatusLine") + +function surround(delimiters, component) + return { + init = function(self) + local highlight + if component.hl ~= nil and type(component.hl) == "function" then + if component.init ~= nil then + component:init() + end + highlight = component:hl() + else + highlight = component.hl + end + + self.inverse = inverseColors(highlight) + self.inverse.ctermfg = StatusLineColor.ctermfg -- Actually sets bg, but both are reversed + end, + + { + condition = function() return conditions.is_active() end, + provider = delimiters[1], + hl = function(self) return self.inverse end, + }, + component, + { + condition = function() return conditions.is_active() end, + provider = delimiters[2], + hl = function(self) return self.inverse end, + }, + + update = { "BufEnter", "BufLeave" }, + } +end + +--[=[ Common elements ]=]-- + +local FileStat = { + { + condition = function() + return vim.bo.readonly + end, + provider = "", + }, + { + condition = function() + return vim.bo.modified or not vim.bo.modifiable + end, + provider = function(self) + local prepend = vim.bo.readonly and " " or "" + if vim.bo.modified then return prepend.."" end + if not vim.bo.modifiable then return prepend.."" end + end, + }, +} + +local FileType = { + static = { + get_icon = require("nvim-web-devicons").get_icon_by_filetype, + }, + provider = function(self) + local icon = self.get_icon(vim.bo.filetype) + if icon ~= nil then icon = icon.." " + else icon = "" + end + return icon..vim.bo.filetype + end, +} + +local Filename = { provider = "%f", } +local Space = { provider = " ", } + +--[=[ Statusline ]=]-- + +vim.cmd.highlight({ "ModeNormal", "ctermfg=236", "ctermbg=117" }) +vim.cmd.highlight({ "ModeInsert", "ctermfg=236", "ctermbg=119" }) +vim.cmd.highlight({ "ModeReplace", "ctermfg=236", "ctermbg=203" }) +vim.cmd.highlight({ "ModeVisual", "ctermfg=236", "ctermbg=216" }) + +local Mode = surround(delimiters.FilledCircle, { + init = function(self) + self.modestr = vim.fn.mode(1) + if self.modestr == "\22" then self.modestr = "V^" + elseif self.modestr == "\22s" then self.modestr = "V^s" + end + end, + + provider = function(self) + if not conditions.is_active() then return " " end + return self.modestr + end, + hl = function(self) + if not conditions.is_active() then return "StatusLineNC" end + + local modeletter = self.modestr:sub(1,1):lower() + + if modeletter == "i" then return "ModeInsert" + elseif modeletter == "r" then return "ModeReplace" + elseif modeletter == "v" then return "ModeVisual" + end + + return "ModeNormal" + end, +}) + + +vim.cmd.highlight({ "RowAndColumn", "ctermfg=238", "ctermbg=244" }) + +local LineAndColumn = surround(delimiters.FilledCircle, { + provider = function(self) + if not conditions.is_active() then + local row,col = unpack(vim.api.nvim_win_get_cursor(0)) + return string.rep(" ", 1 + tostring(row):len() + tostring(col):len()) + end + return "%l:%c" + end, + hl = function(self) + if not conditions.is_active() then return "StatusLineNC" end + return "RowAndColumn" + end, +}) + +local LeftShrink = { provider = "%<", } +local LeftSep = { provider = " "..delimiters.Circle[2].." " } +local RightSep = { provider = " "..delimiters.Circle[1].." " } +local ExpandMiddle = { provider = "%=", } +local CursorChar = { provider = "%b", } + +local StatusLine = { + Mode, LeftShrink, Space, Filename, LeftSep, FileStat, + ExpandMiddle, + CursorChar, RightSep, FileType, Space, LineAndColumn +} + +--[=[ Setup ]=]-- + +require("heirline").setup({ + statusline = StatusLine, +}) |
