enc: Change buffer line to cookieline

This commit is contained in:
Pojok Code 2025-08-03 15:49:00 +07:00
parent 76277745b3
commit b30a97b80a
5 changed files with 207 additions and 37 deletions

View file

@ -2,13 +2,11 @@
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
"LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" }, "LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" },
"alpha-nvim": { "branch": "main", "commit": "2b3cbcdd980cae1e022409289245053f62fb50f6" }, "alpha-nvim": { "branch": "main", "commit": "2b3cbcdd980cae1e022409289245053f62fb50f6" },
"auto-bufferline.nvim": { "branch": "main", "commit": "6a69520dcb0dc615df3cf972f69027aae3f75c3e" },
"auto-conform.nvim": { "branch": "main", "commit": "5f0897235e84bf2f8ff9d634e81678d5bfa63ab8" }, "auto-conform.nvim": { "branch": "main", "commit": "5f0897235e84bf2f8ff9d634e81678d5bfa63ab8" },
"auto-lint.nvim": { "branch": "main", "commit": "aff13cb8eaa055e66e940d43b7d83166397e5413" }, "auto-lint.nvim": { "branch": "main", "commit": "aff13cb8eaa055e66e940d43b7d83166397e5413" },
"auto-lsp.nvim": { "branch": "main", "commit": "f32c94fff2862c313f4e150eb39dd0dc9bf18755" }, "auto-lsp.nvim": { "branch": "main", "commit": "f32c94fff2862c313f4e150eb39dd0dc9bf18755" },
"auto-lualine.nvim": { "branch": "main", "commit": "201da916411a56d0b27905528a7cb49a320ee054" }, "auto-lualine.nvim": { "branch": "main", "commit": "201da916411a56d0b27905528a7cb49a320ee054" },
"breadcrumbs.nvim": { "branch": "master", "commit": "9f764278784ce2f10dbe2f555ba14be2451d36a0" }, "breadcrumbs.nvim": { "branch": "master", "commit": "9f764278784ce2f10dbe2f555ba14be2451d36a0" },
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
"cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" }, "cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" },
"cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" },
@ -35,6 +33,7 @@
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
"nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" },
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
"nvim-cokeline": { "branch": "main", "commit": "9fbed130683b7b6f73198c09e35ba4b33f547c08" },
"nvim-lint": { "branch": "master", "commit": "7ef127aaede2a4d5ad8df8321e2eb4e567f29594" }, "nvim-lint": { "branch": "master", "commit": "7ef127aaede2a4d5ad8df8321e2eb4e567f29594" },
"nvim-lspconfig": { "branch": "master", "commit": "d0dbf489a8810672fa9a61f4a86e5cf89214b772" }, "nvim-lspconfig": { "branch": "master", "commit": "d0dbf489a8810672fa9a61f4a86e5cf89214b772" },
"nvim-material-icon": { "branch": "main", "commit": "c25a4e56be2f846dfdf8f30b980adc17f219d019" }, "nvim-material-icon": { "branch": "main", "commit": "c25a4e56be2f846dfdf8f30b980adc17f219d019" },

View file

@ -4,6 +4,6 @@ require("pcode.config.lazy_lib")
require("pcode.user.colorscheme") require("pcode.user.colorscheme")
require("pcode.core.neovide") require("pcode.core.neovide")
vim.keymap.set({ "n", "v", "x" }, "<C-i>", function() --[[ vim.keymap.set({ "n", "v", "x" }, "<C-i>", function()
require("gemini").ask_gemini() require("gemini").ask_gemini()
end, { noremap = true, silent = true, desc = "Prompt Gemini CLI" }) end, { noremap = true, silent = true, desc = "Prompt Gemini CLI" }) ]]

View file

@ -1,15 +1,114 @@
return { return {
"akinsho/bufferline.nvim", "willothy/nvim-cokeline",
branch = "main", event = { "BufRead", "BufNewFile" },
event = { "BufRead", "InsertEnter", "BufNewFile" }, opts = function()
dependencies = "pojokcodeid/auto-bufferline.nvim", local truncate_text = function(text, max_length)
config = function() if #text > max_length then
vim.opt.termguicolors = true return text:sub(1, max_length) .. "..."
local config = require("auto-bufferline").config() else
require("bufferline").setup(config) return text
end
end
local yellow = vim.g.terminal_color_3
local hlgroups = require("cokeline.hlgroups")
local hl_attr = hlgroups.get_hl_attr
return {
sidebar = {
filetype = { "NvimTree", "neo-tree" },
components = {
{
text = "",
fg = hl_attr("CursorLine", "bg"),
bg = hl_attr("Normal", "bg"),
},
{
text = " Explorer ",
fg = yellow,
bg = function()
return hl_attr("CursorLine", "bg")
end,
bold = true,
},
{
text = "",
fg = hl_attr("CursorLine", "bg"),
bg = hl_attr("Normal", "bg"),
},
},
},
default_hl = {
fg = function(buffer)
return buffer.is_focused and hl_attr("Normal", "fg") or hl_attr("Comment", "fg")
end,
bg = function(buffer)
return buffer.is_focused and hl_attr("CursorLine", "bg") or hl_attr("Normal", "bg")
end,
},
components = {
{
text = "",
fg = hl_attr("Comment", "fg"),
bg = hl_attr("Normal", "bg"),
},
{
text = "",
fg = function(buffer)
return buffer.is_focused and hl_attr("CursorLine", "bg") or hl_attr("Normal", "bg")
end,
bg = hl_attr("Normal", "bg"),
},
{
text = function(buffer)
return buffer.devicon.icon
end,
fg = function(buffer)
return buffer.devicon.color
end,
},
{
text = " ",
},
{
text = function(buffer)
return truncate_text(buffer.filename, 12) .. " "
end,
style = function(buffer)
return buffer.is_focused and "bold" or nil
end,
italic = function(buffer)
return buffer.is_focused and true or nil
end,
},
{
text = "󰅖",
delete_buffer_on_left_click = true,
},
{
text = "",
fg = function(buffer)
return buffer.is_focused and hl_attr("CursorLine", "bg") or hl_attr("Normal", "bg")
end,
bg = hl_attr("Normal", "bg"),
},
},
}
end, end,
keys = { keys = {
{ "<leader>b", "", desc = "  Buffers", mode = "n" }, { "<leader>b", "", desc = "  Buffers", mode = "n" },
{
"<Leader>bp",
"<Plug>(cokeline-switch-prev)",
desc = "Focus Previous buffer",
mode = "n",
},
{
"<Leader>bn",
"<Plug>(cokeline-switch-next)",
desc = "Focus next buffer",
mode = "n",
},
{ {
"<leader>bb", "<leader>bb",
function() function()
@ -21,14 +120,42 @@ return {
{ {
"<leader>bc", "<leader>bc",
function() function()
require("auto-bufferline.configs.utils").bufremove() require("pcode.user.buffer").bufremove()
end, end,
desc = "Close current buffer", desc = "Close current buffer",
mode = "n", mode = "n",
}, },
{ "<leader>bd", "<cmd>BufferLineCloseLeft<cr>", desc = "Close Buffer Left", mode = "n" }, {
{ "<leader>bD", "<cmd>BufferLineCloseRight<cr>", desc = "Close Buffer Right", mode = "n" }, "<S-Tab>",
{ "<leader>ba", "<cmd>BufferLineCloseOthers<cr>", desc = "Close Buffer Other", mode = "n" }, "<Plug>(cokeline-focus-prev)",
{ "<leader>bA", "<cmd>BufferLineCloseOthers<cr><cmd>bd!<cr>", desc = "Close Buffer All", mode = "n" }, desc = "Focus previous buffer",
mode = "n",
},
{
"<Tab>",
"<Plug>(cokeline-focus-next)",
desc = "Focus buffer Next",
mode = "n",
},
{
"<S-PageUp>",
"<Plug>(cokeline-switch-prev)",
desc = "Switch to previous buffer",
mode = "n",
},
{
"<S-PageDown>",
"<Plug>(cokeline-switch-next)",
desc = "Switch to next buffer",
mode = "n",
},
{
"<S-t>",
function()
require("pcode.user.buffer").bufremove()
end,
desc = "Close Current Buffer",
mode = "n",
},
}, },
} }

44
lua/pcode/user/buffer.lua Normal file
View file

@ -0,0 +1,44 @@
local M = {}
function M.bufremove(buf)
buf = buf or 0
buf = buf == 0 and vim.api.nvim_get_current_buf() or buf
if vim.bo.modified then
local choice = vim.fn.confirm(("Save changes to %q?"):format(vim.fn.bufname()), "&Yes\n&No\n&Cancel")
if choice == 0 then -- Cancel
return
end
if choice == 1 then -- Yes
vim.cmd.write()
end
end
for _, win in ipairs(vim.fn.win_findbuf(buf)) do
vim.api.nvim_win_call(win, function()
if not vim.api.nvim_win_is_valid(win) or vim.api.nvim_win_get_buf(win) ~= buf then
return
end
-- Try using alternate buffer
local alt = vim.fn.bufnr("#")
if alt ~= buf and vim.fn.buflisted(alt) == 1 then
vim.api.nvim_win_set_buf(win, alt)
return
end
-- Try using previous buffer
local has_previous = pcall(vim.cmd, "bprevious")
if has_previous and buf ~= vim.api.nvim_win_get_buf(win) then
return
end
-- Create new listed buffer
local new_buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_win_set_buf(win, new_buf)
end)
end
if vim.api.nvim_buf_is_valid(buf) then
pcall(vim.cmd, "bdelete! " .. buf)
end
end
return M

View file

@ -18,7 +18,7 @@ return {
opts = { opts = {
-- for more options check out https://github.com/pojokcodeid/auto-lualine.nvim -- for more options check out https://github.com/pojokcodeid/auto-lualine.nvim
setColor = "auto", setColor = "auto",
setOption = "parallelogram", setOption = "roundedall",
setMode = 5, setMode = 5,
}, },
}, },