BREAKING Change for statusline_separator & tabufline overriders
moved statusline & tabufline into a new plugin to keep the base config clean and fix issues like (#1307)
This commit is contained in:
parent
fa68c66454
commit
74f2efca9f
14 changed files with 53 additions and 627 deletions
|
@ -20,19 +20,6 @@ M.ui = {
|
|||
theme_toggle = { "onedark", "one_light" },
|
||||
theme = "onedark", -- default theme
|
||||
transparency = false,
|
||||
|
||||
statusline = {
|
||||
separator_style = "default", -- default/round/block/arrow
|
||||
config = "%!v:lua.require('ui.statusline').run()",
|
||||
override = {},
|
||||
},
|
||||
|
||||
-- lazyload it when there are 1+ buffers
|
||||
tabufline = {
|
||||
enabled = true,
|
||||
lazyload = true,
|
||||
override = {},
|
||||
},
|
||||
}
|
||||
|
||||
M.plugins = {
|
||||
|
|
|
@ -44,8 +44,10 @@ autocmd("BufEnter", {
|
|||
command = "set fo-=c fo-=r fo-=o",
|
||||
})
|
||||
|
||||
-- store listed buffers in tab local var
|
||||
vim.t.bufs = vim.api.nvim_list_bufs()
|
||||
|
||||
-- autocmds for tabufline -> store bufnrs on bufadd, bufenter events
|
||||
-- thx to https://github.com/ii14 & stores buffer per tab -> table
|
||||
autocmd({ "BufAdd", "BufEnter" }, {
|
||||
callback = function(args)
|
||||
|
@ -79,12 +81,3 @@ autocmd("BufDelete", {
|
|||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local tabufline_opts = require("core.utils").load_config().ui.tabufline
|
||||
|
||||
if tabufline_opts.enabled and tabufline_opts.lazyload then
|
||||
require("core.lazy_load").tabufline()
|
||||
elseif tabufline_opts.enabled then
|
||||
vim.opt.showtabline = 2
|
||||
vim.opt.tabline = "%!v:lua.require'ui.tabline'.run()"
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
local M = {}
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
-- This must be used for plugins that need to be loaded just after a file
|
||||
-- ex : treesitter, lspconfig etc
|
||||
M.lazy_load = function(tb)
|
||||
autocmd(tb.events, {
|
||||
pattern = "*",
|
||||
|
@ -107,18 +109,4 @@ M.gitsigns = function()
|
|||
})
|
||||
end
|
||||
|
||||
M.tabufline = function()
|
||||
autocmd({ "BufNewFile", "BufRead", "TabEnter" }, {
|
||||
pattern = "*",
|
||||
group = vim.api.nvim_create_augroup("TabuflineLazyLoad", {}),
|
||||
callback = function()
|
||||
if #vim.fn.getbufinfo { buflisted = 1 } >= 2 then
|
||||
vim.opt.showtabline = 2
|
||||
vim.opt.tabline = "%!v:lua.require'ui.tabline'.run()"
|
||||
vim.api.nvim_del_augroup_by_name "TabuflineLazyLoad"
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -12,7 +12,6 @@ g.did_load_filetypes = 0
|
|||
g.do_filetype_lua = 1
|
||||
|
||||
opt.laststatus = 3 -- global statusline
|
||||
opt.statusline = config.ui.statusline.config
|
||||
opt.showmode = false
|
||||
|
||||
opt.title = true
|
||||
|
|
|
@ -47,7 +47,7 @@ local options = {
|
|||
},
|
||||
formatting = {
|
||||
format = function(_, vim_item)
|
||||
local icons = require("ui.icons").lspkind
|
||||
local icons = require("nvchad_ui.icons").lspkind
|
||||
vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
|
||||
return vim_item
|
||||
end,
|
||||
|
|
|
@ -5,12 +5,11 @@ if not present then
|
|||
end
|
||||
|
||||
require("base46").load_highlight "lsp"
|
||||
require "nvchad_ui.lsp"
|
||||
|
||||
local M = {}
|
||||
local utils = require "core.utils"
|
||||
|
||||
require "ui.lsp"
|
||||
|
||||
M.on_attach = function(client, bufnr)
|
||||
local vim_version = vim.version()
|
||||
|
||||
|
|
40
lua/plugins/configs/nvchad_ui.lua
Normal file
40
lua/plugins/configs/nvchad_ui.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
local present, _ = pcall(require, "nvchad_ui")
|
||||
|
||||
if not present then
|
||||
return
|
||||
end
|
||||
|
||||
local options = {
|
||||
|
||||
statusline = {
|
||||
separator_style = "default", -- default/round/block/arrow
|
||||
overriden_modules = nil,
|
||||
},
|
||||
|
||||
-- lazyload it when there are 1+ buffers
|
||||
tabufline = {
|
||||
enabled = true,
|
||||
lazyload = true,
|
||||
overriden_modules = nil,
|
||||
},
|
||||
}
|
||||
|
||||
options = require("core.utils").load_override(options, "NvChad/ui")
|
||||
|
||||
require "nvchad_ui.tabufline.lazyload"(options.tabufline)
|
||||
|
||||
-- ignore this as it might scare you XD
|
||||
return {
|
||||
statusline = function()
|
||||
return require("nvchad_ui.statusline").setup(options)
|
||||
end,
|
||||
|
||||
tabufline = function()
|
||||
return require("nvchad_ui.tabufline").setup(options)
|
||||
end,
|
||||
|
||||
load_ui_plugins = function()
|
||||
vim.opt.statusline = "%!v:lua.require('plugins.configs.nvchad_ui').statusline()"
|
||||
vim.opt.tabline = "%!v:lua.require('plugins.configs.nvchad_ui').tabufline()"
|
||||
end,
|
||||
}
|
|
@ -155,7 +155,7 @@ M.devicons = function()
|
|||
if present then
|
||||
require("base46").load_highlight "devicons"
|
||||
|
||||
local options = { override = require("ui.icons").devicons }
|
||||
local options = { override = require("nvchad_ui.icons").devicons }
|
||||
options = require("core.utils").load_override(options, "kyazdani42/nvim-web-devicons")
|
||||
|
||||
devicons.setup(options)
|
||||
|
|
|
@ -16,7 +16,12 @@ local plugins = {
|
|||
end,
|
||||
},
|
||||
|
||||
["Nvchad/ui"] = {},
|
||||
["NvChad/ui"] = {
|
||||
after = "base46",
|
||||
config = function()
|
||||
require("plugins.configs.nvchad_ui").load_ui_plugins()
|
||||
end,
|
||||
},
|
||||
|
||||
["NvChad/nvterm"] = {
|
||||
module = "nvterm",
|
||||
|
|
207
lua/ui/icons.lua
207
lua/ui/icons.lua
|
@ -1,207 +0,0 @@
|
|||
local M = {}
|
||||
|
||||
M.lspkind = {
|
||||
Namespace = "",
|
||||
Text = " ",
|
||||
Method = " ",
|
||||
Function = " ",
|
||||
Constructor = " ",
|
||||
Field = "ﰠ ",
|
||||
Variable = " ",
|
||||
Class = "ﴯ ",
|
||||
Interface = " ",
|
||||
Module = " ",
|
||||
Property = "ﰠ ",
|
||||
Unit = "塞 ",
|
||||
Value = " ",
|
||||
Enum = " ",
|
||||
Keyword = " ",
|
||||
Snippet = " ",
|
||||
Color = " ",
|
||||
File = " ",
|
||||
Reference = " ",
|
||||
Folder = " ",
|
||||
EnumMember = " ",
|
||||
Constant = " ",
|
||||
Struct = "פּ ",
|
||||
Event = " ",
|
||||
Operator = " ",
|
||||
TypeParameter = " ",
|
||||
Table = "",
|
||||
Object = " ",
|
||||
Tag = "",
|
||||
Array = "[]",
|
||||
Boolean = " ",
|
||||
Number = " ",
|
||||
Null = "ﳠ",
|
||||
String = " ",
|
||||
Calendar = "",
|
||||
Watch = " ",
|
||||
Package = "",
|
||||
}
|
||||
|
||||
M.statusline_separators = {
|
||||
default = {
|
||||
left = "",
|
||||
right = " ",
|
||||
},
|
||||
|
||||
round = {
|
||||
left = "",
|
||||
right = "",
|
||||
},
|
||||
|
||||
block = {
|
||||
left = "█",
|
||||
right = "█",
|
||||
},
|
||||
|
||||
arrow = {
|
||||
left = "",
|
||||
right = "",
|
||||
},
|
||||
}
|
||||
|
||||
M.devicons = {
|
||||
default_icon = {
|
||||
icon = "",
|
||||
name = "Default",
|
||||
},
|
||||
|
||||
c = {
|
||||
icon = "",
|
||||
name = "c",
|
||||
},
|
||||
|
||||
css = {
|
||||
icon = "",
|
||||
name = "css",
|
||||
},
|
||||
|
||||
deb = {
|
||||
icon = "",
|
||||
name = "deb",
|
||||
},
|
||||
|
||||
Dockerfile = {
|
||||
icon = "",
|
||||
name = "Dockerfile",
|
||||
},
|
||||
|
||||
html = {
|
||||
icon = "",
|
||||
name = "html",
|
||||
},
|
||||
|
||||
jpeg = {
|
||||
icon = "",
|
||||
name = "jpeg",
|
||||
},
|
||||
|
||||
jpg = {
|
||||
icon = "",
|
||||
name = "jpg",
|
||||
},
|
||||
|
||||
js = {
|
||||
icon = "",
|
||||
name = "js",
|
||||
},
|
||||
|
||||
kt = {
|
||||
icon = "",
|
||||
name = "kt",
|
||||
},
|
||||
|
||||
lock = {
|
||||
icon = "",
|
||||
name = "lock",
|
||||
},
|
||||
|
||||
lua = {
|
||||
icon = "",
|
||||
name = "lua",
|
||||
},
|
||||
|
||||
mp3 = {
|
||||
icon = "",
|
||||
name = "mp3",
|
||||
},
|
||||
|
||||
mp4 = {
|
||||
icon = "",
|
||||
name = "mp4",
|
||||
},
|
||||
|
||||
out = {
|
||||
icon = "",
|
||||
name = "out",
|
||||
},
|
||||
|
||||
png = {
|
||||
icon = "",
|
||||
name = "png",
|
||||
},
|
||||
|
||||
py = {
|
||||
icon = "",
|
||||
name = "py",
|
||||
},
|
||||
|
||||
["robots.txt"] = {
|
||||
icon = "ﮧ",
|
||||
name = "robots",
|
||||
},
|
||||
|
||||
toml = {
|
||||
icon = "",
|
||||
name = "toml",
|
||||
},
|
||||
|
||||
ts = {
|
||||
icon = "ﯤ",
|
||||
name = "ts",
|
||||
},
|
||||
|
||||
ttf = {
|
||||
icon = "",
|
||||
name = "TrueTypeFont",
|
||||
},
|
||||
|
||||
rb = {
|
||||
icon = "",
|
||||
name = "rb",
|
||||
},
|
||||
|
||||
rpm = {
|
||||
icon = "",
|
||||
name = "rpm",
|
||||
},
|
||||
|
||||
vue = {
|
||||
icon = "﵂",
|
||||
name = "vue",
|
||||
},
|
||||
|
||||
woff = {
|
||||
icon = "",
|
||||
name = "WebOpenFontFormat",
|
||||
},
|
||||
|
||||
woff2 = {
|
||||
icon = "",
|
||||
name = "WebOpenFontFormat2",
|
||||
},
|
||||
|
||||
xz = {
|
||||
icon = "",
|
||||
name = "xz",
|
||||
},
|
||||
|
||||
zip = {
|
||||
icon = "",
|
||||
name = "zip",
|
||||
},
|
||||
}
|
||||
|
||||
return M
|
|
@ -1,49 +0,0 @@
|
|||
local function lspSymbol(name, icon)
|
||||
local hl = "DiagnosticSign" .. name
|
||||
vim.fn.sign_define(hl, { text = icon, numhl = hl, texthl = hl })
|
||||
end
|
||||
|
||||
lspSymbol("Error", "")
|
||||
lspSymbol("Info", "")
|
||||
lspSymbol("Hint", "")
|
||||
lspSymbol("Warn", "")
|
||||
|
||||
vim.diagnostic.config {
|
||||
virtual_text = {
|
||||
prefix = "",
|
||||
},
|
||||
signs = true,
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
}
|
||||
|
||||
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||
border = "single",
|
||||
})
|
||||
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
||||
border = "single",
|
||||
focusable = false,
|
||||
relative = "cursor",
|
||||
})
|
||||
|
||||
-- suppress error messages from lang servers
|
||||
vim.notify = function(msg, log_level)
|
||||
if msg:match "exit code" then
|
||||
return
|
||||
end
|
||||
if log_level == vim.log.levels.ERROR then
|
||||
vim.api.nvim_err_writeln(msg)
|
||||
else
|
||||
vim.api.nvim_echo({ { msg } }, true, {})
|
||||
end
|
||||
end
|
||||
|
||||
-- Borders for LspInfo winodw
|
||||
local win = require "lspconfig.ui.windows"
|
||||
local _default_opts = win.default_opts
|
||||
|
||||
win.default_opts = function(options)
|
||||
local opts = _default_opts(options)
|
||||
opts.border = "single"
|
||||
return opts
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
local modules = require "ui.statusline.modules"
|
||||
local user_override = require("core.utils").load_config().ui.statusline.override
|
||||
modules = vim.tbl_deep_extend("force", modules, user_override)
|
||||
|
||||
return {
|
||||
run = function()
|
||||
return table.concat {
|
||||
modules.mode(),
|
||||
modules.fileInfo(),
|
||||
modules.git(),
|
||||
|
||||
"%=",
|
||||
modules.LSP_progress(),
|
||||
"%=",
|
||||
|
||||
modules.LSP_Diagnostics(),
|
||||
modules.LSP_status() or "",
|
||||
modules.cwd(),
|
||||
modules.cursor_position(),
|
||||
}
|
||||
end,
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
local fn = vim.fn
|
||||
local sep_style = require("ui.icons").statusline_separators
|
||||
local user_sep = require("core.utils").load_config().ui.statusline.separator_style
|
||||
local sep_l = sep_style[user_sep]["left"]
|
||||
local sep_r = sep_style[user_sep]["right"]
|
||||
|
||||
local modes = {
|
||||
["n"] = { "NORMAL", "St_NormalMode" },
|
||||
["niI"] = { "NORMAL i", "St_NormalMode" },
|
||||
["niR"] = { "NORMAL r", "St_NormalMode" },
|
||||
["niV"] = { "NORMAL v", "St_NormalMode" },
|
||||
["no"] = { "N-PENDING", "St_NormalMode" },
|
||||
["i"] = { "INSERT", "St_InsertMode" },
|
||||
["ic"] = { "INSERT", "St_InsertMode" },
|
||||
["ix"] = { "INSERT completion", "St_InsertMode" },
|
||||
["t"] = { "TERMINAL", "St_TerminalMode" },
|
||||
["nt"] = { "NTERMINAL", "St_NTerminalMode" },
|
||||
["v"] = { "VISUAL", "St_VisualMode" },
|
||||
["V"] = { "V-LINE", "St_VisualMode" },
|
||||
[""] = { "V-BLOCK", "St_VisualMode" },
|
||||
["R"] = { "REPLACE", "St_ReplaceMode" },
|
||||
["Rv"] = { "V-REPLACE", "St_ReplaceMode" },
|
||||
["s"] = { "SELECT", "St_SelectMode" },
|
||||
["S"] = { "S-LINE", "St_SelectMode" },
|
||||
[""] = { "S-BLOCK", "St_SelectMode" },
|
||||
["c"] = { "COMMAND", "St_CommandMode" },
|
||||
["cv"] = { "COMMAND", "St_CommandMode" },
|
||||
["ce"] = { "COMMAND", "St_CommandMode" },
|
||||
["r"] = { "PROMPT", "St_ConfirmMode" },
|
||||
["rm"] = { "MORE", "St_ConfirmMode" },
|
||||
["r?"] = { "CONFIRM", "St_ConfirmMode" },
|
||||
["!"] = { "SHELL", "St_TerminalMode" },
|
||||
}
|
||||
|
||||
local M = {}
|
||||
|
||||
M.mode = function()
|
||||
local m = vim.api.nvim_get_mode().mode
|
||||
local current_mode = "%#" .. modes[m][2] .. "#" .. " " .. modes[m][1]
|
||||
local mode_sep1 = "%#" .. modes[m][2] .. "Sep" .. "#" .. sep_r
|
||||
|
||||
return current_mode .. mode_sep1 .. "%#ST_EmptySpace#" .. sep_r
|
||||
end
|
||||
|
||||
M.fileInfo = function()
|
||||
local icon = " "
|
||||
local filename = (fn.expand "%" == "" and "Empty ") or fn.expand "%:t"
|
||||
|
||||
if filename ~= "Empty " then
|
||||
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
||||
|
||||
if devicons_present then
|
||||
local ft_icon = devicons.get_icon(filename)
|
||||
icon = (ft_icon ~= nil and " " .. ft_icon) or ""
|
||||
end
|
||||
|
||||
filename = " " .. filename .. " "
|
||||
end
|
||||
|
||||
return "%#St_file_info#" .. icon .. filename .. "%#St_file_sep#" .. sep_r
|
||||
end
|
||||
|
||||
M.git = function()
|
||||
if not vim.b.gitsigns_head or vim.b.gitsigns_git_status then
|
||||
return ""
|
||||
end
|
||||
|
||||
local git_status = vim.b.gitsigns_status_dict
|
||||
|
||||
local added = (git_status.added and git_status.added ~= 0) and (" " .. git_status.added) or ""
|
||||
local changed = (git_status.changed and git_status.changed ~= 0) and (" " .. git_status.changed) or ""
|
||||
local removed = (git_status.removed and git_status.removed ~= 0) and (" " .. git_status.removed) or ""
|
||||
local branch_name = " " .. git_status.head .. " "
|
||||
|
||||
return "%#St_gitIcons#" .. branch_name .. added .. changed .. removed
|
||||
end
|
||||
|
||||
-- LSP STUFF
|
||||
M.LSP_progress = function()
|
||||
local Lsp = vim.lsp.util.get_progress_messages()[1]
|
||||
|
||||
if vim.o.columns < 120 or not Lsp then
|
||||
return ""
|
||||
end
|
||||
|
||||
local msg = Lsp.message or ""
|
||||
local percentage = Lsp.percentage or 0
|
||||
local title = Lsp.title or ""
|
||||
local spinners = { "", "" }
|
||||
local ms = vim.loop.hrtime() / 1000000
|
||||
local frame = math.floor(ms / 120) % #spinners
|
||||
local content = string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
|
||||
|
||||
return ("%#St_LspProgress#" .. content) or ""
|
||||
end
|
||||
|
||||
M.LSP_Diagnostics = function()
|
||||
local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
|
||||
local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
|
||||
local hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT })
|
||||
local info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO })
|
||||
|
||||
errors = (errors and errors > 0) and ("%#St_lspError#" .. " " .. errors .. " ") or ""
|
||||
warnings = (warnings and warnings > 0) and ("%#St_lspWarning#" .. " " .. warnings .. " ") or ""
|
||||
hints = (hints and hints > 0) and ("%#St_lspHints#" .. "ﯧ " .. hints .. " ") or ""
|
||||
info = (info and info > 0) and ("%#St_lspInfo#" .. " " .. info .. " ") or ""
|
||||
|
||||
return errors .. warnings .. hints .. info
|
||||
end
|
||||
|
||||
M.LSP_status = function()
|
||||
for _, client in ipairs(vim.lsp.get_active_clients()) do
|
||||
if client.attached_buffers[vim.api.nvim_get_current_buf()] then
|
||||
return (vim.o.columns > 70 and "%#St_LspStatus#" .. " LSP ~ " .. client.name .. " ") or " LSP "
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
M.cwd = function()
|
||||
local dir_icon = "%#St_cwd_icon#" .. " "
|
||||
local dir_name = "%#St_cwd_text#" .. " " .. fn.fnamemodify(fn.getcwd(), ":t") .. " "
|
||||
return (vim.o.columns > 120 and ("%#St_cwd_sep#" .. sep_l .. dir_icon .. dir_name)) or ""
|
||||
end
|
||||
|
||||
M.cursor_position = function()
|
||||
local left_sep = "%#St_pos_sep#" .. sep_l .. "%#St_pos_icon#" .. " "
|
||||
|
||||
local current_line = fn.line "."
|
||||
local total_line = fn.line "$"
|
||||
local text = math.modf((current_line / total_line) * 100) .. tostring "%%"
|
||||
|
||||
text = (current_line == 1 and "Top") or text
|
||||
text = (current_line == total_line and "Bot") or text
|
||||
|
||||
return left_sep .. "%#St_pos_text#" .. " " .. text .. " "
|
||||
end
|
||||
|
||||
return M
|
|
@ -1,169 +0,0 @@
|
|||
local api = vim.api
|
||||
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
||||
local fn = vim.fn
|
||||
local new_cmd = api.nvim_create_user_command
|
||||
|
||||
require("base46").load_highlight "tbline"
|
||||
|
||||
---------------------------------------------------------- btn onclick functions ----------------------------------------------
|
||||
|
||||
vim.cmd "function! TbGoToBuf(bufnr,b,c,d) \n execute 'b'..a:bufnr \n endfunction"
|
||||
|
||||
vim.cmd [[
|
||||
function! TbKillBuf(bufnr,b,c,d)
|
||||
call luaeval('require("core.utils").close_buffer(_A)', a:bufnr)
|
||||
endfunction]]
|
||||
|
||||
vim.cmd "function! TbNewTab(a,b,c,d) \n tabnew \n endfunction"
|
||||
vim.cmd "function! TbGotoTab(tabnr,b,c,d) \n execute a:tabnr ..'tabnext' \n endfunction"
|
||||
vim.cmd "function! TbTabClose(a,b,c,d) \n lua require('core.utils').closeAllBufs('closeTab') \n endfunction"
|
||||
vim.cmd "function! TbCloseAllBufs(a,b,c,d) \n lua require('core.utils').closeAllBufs() \n endfunction"
|
||||
vim.cmd "function! TbToggle_theme(a,b,c,d) \n lua require('base46').toggle_theme() \n endfunction"
|
||||
vim.cmd "function! TbToggleTabs(a,b,c,d) \n let g:TbTabsToggled = !g:TbTabsToggled | redrawtabline \n endfunction"
|
||||
|
||||
---------------------------------------------------------- commands ------------------------------------------------------------
|
||||
new_cmd("Tbufnext", function()
|
||||
require("core.utils").tabuflineNext()
|
||||
end, {})
|
||||
|
||||
new_cmd("Tbufprev", function()
|
||||
require("core.utils").tabuflinePrev()
|
||||
end, {})
|
||||
|
||||
new_cmd("Tbufclose", function()
|
||||
require("core.utils").close_buffer()
|
||||
end, {})
|
||||
|
||||
-------------------------------------------------------- functions ------------------------------------------------------------
|
||||
local function new_hl(group1, group2)
|
||||
local fg = fn.synIDattr(fn.synIDtrans(fn.hlID(group1)), "fg#")
|
||||
local bg = fn.synIDattr(fn.synIDtrans(fn.hlID(group2)), "bg#")
|
||||
api.nvim_set_hl(0, "Tbline" .. group1 .. group2, { fg = fg, bg = bg })
|
||||
return "%#" .. "Tbline" .. group1 .. group2 .. "#"
|
||||
end
|
||||
|
||||
local function getNvimTreeWidth()
|
||||
for _, win in pairs(api.nvim_tabpage_list_wins(0)) do
|
||||
if vim.bo[api.nvim_win_get_buf(win)].ft == "NvimTree" then
|
||||
return api.nvim_win_get_width(win) + 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function getBtnsWidth()
|
||||
local width = 6
|
||||
if fn.tabpagenr "$" ~= 1 then
|
||||
width = width + ((3 * fn.tabpagenr "$") + 2) + 10
|
||||
width = not vim.g.TbTabsToggled and 8 or width
|
||||
end
|
||||
return width
|
||||
end
|
||||
|
||||
local function add_fileInfo(name, bufnr)
|
||||
if devicons_present then
|
||||
local icon, icon_hl = devicons.get_icon(name, string.match(name, "%a+$"))
|
||||
|
||||
if not icon then
|
||||
icon, icon_hl = devicons.get_icon "default_icon"
|
||||
end
|
||||
|
||||
local fileInfo = " " .. icon .. " " .. name .. " " -- initial value
|
||||
local pad = (24 - #fileInfo) / 2
|
||||
|
||||
icon = (
|
||||
api.nvim_get_current_buf() == bufnr and new_hl(icon_hl, "TbLineBufOn") .. " " .. icon
|
||||
or new_hl(icon_hl, "TbLineBufOff") .. " " .. icon
|
||||
)
|
||||
|
||||
name = (#name > 15 and string.sub(name, 1, 13) .. "..") or name
|
||||
name = (api.nvim_get_current_buf() == bufnr and "%#TbLineBufOn# " .. name .. " ")
|
||||
or ("%#TbLineBufOff# " .. name .. " ")
|
||||
|
||||
return string.rep(" ", pad) .. icon .. name .. string.rep(" ", pad - 1)
|
||||
end
|
||||
end
|
||||
|
||||
local function styleBufferTab(nr)
|
||||
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
|
||||
local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t") or " No Name "
|
||||
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
|
||||
|
||||
-- color close btn for focused / hidden buffers
|
||||
if nr == api.nvim_get_current_buf() then
|
||||
close_btn = (vim.bo[0].modified and "%" .. nr .. "@TbKillBuf@%#TbLineBufOnModified# ")
|
||||
or ("%#TbLineBufOnClose#" .. close_btn)
|
||||
name = "%#TbLineBufOn#" .. name .. close_btn
|
||||
else
|
||||
close_btn = (vim.bo[nr].modified and "%" .. nr .. "@TbKillBuf@%#TbBufLineBufOffModified# ")
|
||||
or ("%#TbLineBufOffClose#" .. close_btn)
|
||||
name = "%#TbLineBufOff#" .. name .. close_btn
|
||||
end
|
||||
|
||||
return name
|
||||
end
|
||||
|
||||
---------------------------------------------------------- components ------------------------------------------------------------
|
||||
local M = {}
|
||||
|
||||
M.CoverNvimTree = function()
|
||||
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
|
||||
end
|
||||
|
||||
M.bufferlist = function()
|
||||
local buffers = {} -- buffersults
|
||||
local available_space = vim.o.columns - getNvimTreeWidth() - getBtnsWidth()
|
||||
local current_buf = api.nvim_get_current_buf()
|
||||
local has_current = false -- have we seen current buffer yet?
|
||||
|
||||
for _, bufnr in ipairs(vim.t.bufs) do
|
||||
if api.nvim_buf_is_valid(bufnr) then
|
||||
if ((#buffers + 1) * 21) > available_space then
|
||||
if has_current then
|
||||
break
|
||||
end
|
||||
|
||||
table.remove(buffers, 1)
|
||||
end
|
||||
|
||||
has_current = (bufnr == current_buf and true) or has_current
|
||||
table.insert(buffers, styleBufferTab(bufnr))
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(buffers) .. "%#TblineFill#" .. "%=" -- buffers + empty space
|
||||
end
|
||||
|
||||
vim.g.TbTabsToggled = 0
|
||||
|
||||
M.tablist = function()
|
||||
local result, number_of_tabs = "", fn.tabpagenr "$"
|
||||
|
||||
if number_of_tabs > 1 then
|
||||
for i = 1, number_of_tabs, 1 do
|
||||
local tab_hl = ((i == fn.tabpagenr()) and "%#TbLineTabOn# ") or "%#TbLineTabOff# "
|
||||
result = result .. ("%" .. i .. "@TbGotoTab@" .. tab_hl .. i .. " ")
|
||||
result = (i == fn.tabpagenr() and result .. "%#TbLineTabCloseBtn#" .. "%@TbTabClose@ %X") or result
|
||||
end
|
||||
|
||||
local new_tabtn = "%#TblineTabNewBtn#" .. "%@TbNewTab@ %X"
|
||||
local tabstoggleBtn = "%@TbToggleTabs@ %#TBTabTitle# TABS %X"
|
||||
|
||||
return vim.g.TbTabsToggled == 1 and tabstoggleBtn:gsub("()", { [36] = " " })
|
||||
or new_tabtn .. tabstoggleBtn .. result
|
||||
end
|
||||
end
|
||||
|
||||
M.buttons = function()
|
||||
local toggle_themeBtn = "%@TbToggle_theme@%#TbLineThemeToggleBtn#" .. vim.g.toggle_theme_icon .. "%X"
|
||||
local CloseAllBufsBtn = "%@TbCloseAllBufs@%#TbLineCloseAllBufsBtn#" .. " " .. "%X"
|
||||
return toggle_themeBtn .. CloseAllBufsBtn
|
||||
end
|
||||
|
||||
M.run = function()
|
||||
return M.CoverNvimTree() .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
|
||||
end
|
||||
|
||||
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.tabufline.override)
|
||||
|
||||
return M
|
Loading…
Reference in a new issue