mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-25 10:18:47 +02:00
feat(ui): fancy status column
This commit is contained in:
parent
3f868aa825
commit
364bcf325d
2 changed files with 59 additions and 0 deletions
|
@ -61,6 +61,8 @@ else
|
||||||
end
|
end
|
||||||
if vim.treesitter.foldtext then
|
if vim.treesitter.foldtext then
|
||||||
vim.opt.foldtext = "v:lua.vim.treesitter.foldtext()"
|
vim.opt.foldtext = "v:lua.vim.treesitter.foldtext()"
|
||||||
|
if vim.fn.has("nvim-0.9.0") == 1 then
|
||||||
|
vim.opt.statuscolumn = [[%!v:lua.require'lazyvim.util.ui'.statuscolumn()]]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fix markdown indentation settings
|
-- Fix markdown indentation settings
|
||||||
|
|
57
lua/lazyvim/util/ui.lua
Normal file
57
lua/lazyvim/util/ui.lua
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@alias Sign {name:string, text:string, texthl:string}
|
||||||
|
|
||||||
|
---@return Sign[]
|
||||||
|
function M.get_signs(win)
|
||||||
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
|
---@diagnostic disable-next-line: no-unknown
|
||||||
|
return vim.tbl_map(function(sign)
|
||||||
|
return vim.fn.sign_getdefined(sign.name)[1]
|
||||||
|
end, vim.fn.sign_getplaced(buf, { group = "*", lnum = vim.v.lnum })[1].signs)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param sign? Sign
|
||||||
|
---@param len? number
|
||||||
|
function M.icon(sign, len)
|
||||||
|
sign = sign or {}
|
||||||
|
len = len or 1
|
||||||
|
local text = vim.fn.strcharpart(sign.text or "", 0, len, false) ---@type string
|
||||||
|
text = text .. string.rep(" ", len - vim.fn.strchars(text))
|
||||||
|
return sign.texthl and ("%#" .. sign.texthl .. "#" .. text .. "%*") or text
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.statuscolumn()
|
||||||
|
local win = vim.g.statusline_winid
|
||||||
|
if vim.wo[win].signcolumn == "no" then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
---@type Sign?,Sign?,Sign?
|
||||||
|
local left, right, fold
|
||||||
|
for _, s in ipairs(M.get_signs(win)) do
|
||||||
|
if s.name:find("GitSign") then
|
||||||
|
right = s
|
||||||
|
elseif not left then
|
||||||
|
left = s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if vim.fn.foldclosed(vim.v.lnum) >= 0 then
|
||||||
|
fold = { text = vim.opt.fillchars:get().foldclose or "", texthl = "Folded" }
|
||||||
|
end
|
||||||
|
|
||||||
|
local nu = ""
|
||||||
|
if vim.wo[win].number and vim.v.virtnum == 0 then
|
||||||
|
nu = vim.wo[win].relativenumber and vim.v.relnum ~= 0 and vim.v.relnum or vim.v.lnum
|
||||||
|
end
|
||||||
|
|
||||||
|
return table.concat({
|
||||||
|
M.icon(left),
|
||||||
|
[[%=]],
|
||||||
|
nu .. " ",
|
||||||
|
M.icon(fold or right, 2),
|
||||||
|
}, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
Add table
Add a link
Reference in a new issue