LazyVim.LazyVim/lua/lazyvim/util/ui.lua

35 lines
982 B
Lua
Raw Normal View History

---@class lazyvim.util.ui
2023-10-03 14:56:09 +02:00
local M = {}
-- foldtext for Neovim < 0.10.0
2023-10-03 14:56:28 +02:00
function M.foldtext()
return vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1]
end
-- optimized treesitter foldexpr for Neovim >= 0.10.0
function M.foldexpr()
local buf = vim.api.nvim_get_current_buf()
if vim.b[buf].ts_folds == nil then
-- as long as we don't have a filetype, don't bother
-- checking if treesitter is available (it won't)
if vim.bo[buf].filetype == "" then
return "0"
end
if vim.bo[buf].filetype:find("dashboard") then
vim.b[buf].ts_folds = false
else
vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf)
end
end
return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or "0"
2023-10-03 14:56:28 +02:00
end
---@return {fg?:string}?
function M.fg(name)
2024-11-13 21:14:29 +01:00
local hl = vim.api.nvim_get_hl(0, { name = name, link = false })
local fg = hl and hl.fg or hl.foreground
return fg and { fg = string.format("#%06x", fg) } or nil
end
2023-10-03 14:56:09 +02:00
return M