pull/1302/head
siduck 2 years ago
parent 519a2df1a0
commit ae77406a64

@ -5,24 +5,14 @@ local merge_tb = vim.tbl_deep_extend
M.close_buffer = function(bufnr)
if vim.bo.buftype == "terminal" then
if vim.bo.buflisted then
vim.bo.buflisted = false
vim.cmd "enew"
else
vim.cmd "hide"
end
return
end
-- if file doesnt exist & its modified
if vim.bo.modified then
print "save the file!"
return
vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
elseif vim.bo.modified then
print "save the file bruh"
else
bufnr = bufnr or api.nvim_get_current_buf()
require("core.utils").tabuflinePrev()
vim.cmd("bd" .. bufnr)
end
bufnr = bufnr or api.nvim_get_current_buf()
require("core.utils").tabuflinePrev()
vim.cmd("bd" .. bufnr)
end
M.load_config = function()
@ -144,7 +134,6 @@ M.merge_plugins = function(default_plugins)
return final_table
end
M.load_override = function(default_table, plugin_name)
local user_table = M.load_config().plugins.override[plugin_name] or {}
user_table = type(user_table) == "table" and user_table or user_table()
@ -225,13 +214,19 @@ end
-- closes tab + all of its buffers
M.closeAllBufs = function(action)
local bufs = vim.t.bufs or {}
local bufs = vim.t.bufs
if action == "closeTab" then
vim.cmd "tabclose"
end
for _, buf in ipairs(bufs) do
M.close_buffer(buf)
end
vim.cmd(action == "closeTab" and "tabclose" or "enew")
if action ~= "closeTab" then
vim.cmd "enew"
end
end
return M

@ -39,15 +39,20 @@ local function new_hl(group1, group2)
return "%#" .. "Tbline" .. group1 .. group2 .. "#"
end
local M = {}
-- covers area of nvimtree on tabufline
M.Offset = function()
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 "%#NvimTreeNormal#" .. string.rep(" ", api.nvim_win_get_width(win) + 1)
return api.nvim_win_get_width(win) + 1
end
end
return 0
end
local M = {}
-- covers area of nvimtree on tabufline
M.NvimTreeOffset = function()
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
end
local function add_fileInfo(name, bufnr)
@ -66,7 +71,7 @@ local function add_fileInfo(name, bufnr)
or new_hl(icon_hl, "TbLineBufOff") .. " " .. icon
)
name = (#name > 20 and string.sub(name, 1, 15) .. "...") or name
name = (#name > 15 and string.sub(name, 1, 13) .. "..") or name
name = (api.nvim_get_current_buf() == bufnr and "%#TbLineBufOn# " .. name .. " ")
or ("%#TbLineBufOff# " .. name .. " ")
@ -77,24 +82,28 @@ end
M.bufferlist = function()
local buffers = ""
for _, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr
for index, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr
if api.nvim_buf_is_valid(nr) then
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 "
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
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 "%#TbLineBufOnModified# ") or ("%#TbLineBufOnClose#" .. close_btn)
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 "%#TbBufLineBufOffModified# ")
close_btn = (vim.bo[nr].modified and "%" .. nr .. "@TbKillBuf@%#TbBufLineBufOffModified# ")
or ("%#TbLineBufOffClose#" .. close_btn)
name = "%#TbLineBufOff#" .. name .. close_btn
end
buffers = buffers .. name
-- 1 buffer tab = 21 whitespaces
buffers = (21 * index + getNvimTreeWidth() < vim.o.columns - getNvimTreeWidth()) and buffers .. name
or buffers .. ""
end
end
@ -130,7 +139,7 @@ M.buttons = function()
end
M.run = function()
return (M.Offset() or "") .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
return M.NvimTreeOffset() .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
end
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.tabufline.override)

Loading…
Cancel
Save