pojokcodeid.nvim-lazy/lua/user/utils/lualine_component.lua

361 lines
9.7 KiB
Lua
Raw Normal View History

2024-05-21 08:33:21 +07:00
local hide_in_width = function()
2024-05-22 20:42:09 +07:00
return vim.fn.winwidth(0) > 75
2024-05-21 08:33:21 +07:00
end
2024-05-22 20:42:09 +07:00
local icons = require "user.icons"
local formatter = require "user.utils.formatter"
local linter = require "user.utils.linter"
2024-05-21 08:33:21 +07:00
local getLeftSubstring = function(word, length)
2024-05-22 20:42:09 +07:00
if #word > length then
return string.sub(word, 1, length) .. "..."
else
return word
end
2024-05-21 08:33:21 +07:00
end
local unique_list = function(list)
2024-05-22 20:42:09 +07:00
local seen = {}
local result = {}
2024-05-21 08:33:21 +07:00
2024-05-22 20:42:09 +07:00
for _, val in ipairs(list) do
if not seen[val] then
table.insert(result, val)
seen[val] = true
end
end
2024-05-21 08:33:21 +07:00
2024-05-22 20:42:09 +07:00
return result
2024-05-21 08:33:21 +07:00
end
2024-05-29 16:15:20 +07:00
local mode_map = {
["NORMAL"] = "N",
["INSERT"] = "I",
["VISUAL"] = "V",
["REPLACE"] = "R",
["COMMAND"] = "C",
2024-05-30 19:03:34 +07:00
["O-PENDING"] = "O",
2024-05-29 16:15:20 +07:00
}
2024-05-21 08:33:21 +07:00
return {
2024-05-22 20:42:09 +07:00
-- treesitter info
treesitter = {
function()
2024-05-24 08:16:42 +07:00
-- return icons.ui.Paint .. " TS"
return icons.ui.Tree
2024-05-22 20:42:09 +07:00
end,
color = function()
local buf = vim.api.nvim_get_current_buf()
local ts = vim.treesitter.highlighter.active[buf]
return { fg = ts and not vim.tbl_isempty(ts) and "#50fa7b" or "#FF5555" }
end,
cond = hide_in_width,
},
2024-06-05 12:28:31 +07:00
codeium = {
function()
if vim.g.pcode_codeium then
local codeium = all_trim(vim.api.nvim_call_function("codeium#GetStatusString", {}))
if codeium then
-- return " " .. all_trim(codeium)
if codeium == "OFF" then
return icons.kind.CopilotOff
else
return icons.kind.Copilot
end
else
return ""
end
else
return ""
end
end,
color = function()
if vim.g.pcode_codeium then
local codeium = all_trim(vim.api.nvim_call_function("codeium#GetStatusString", {}))
return { fg = codeium == "OFF" and "#3E4452" or "#50fa7b" }
else
return {}
end
end,
cond = hide_in_width,
},
2024-05-22 20:42:09 +07:00
-- Lsp info
lsp_info = {
function()
local msg = "LSP Inactive"
local buf_ft = vim.bo.filetype
-- start register
local buf_clients = {}
buf_clients = vim.lsp.get_clients { bufnr = 0 }
local buf_client_names = {}
if next(buf_clients) == nil then
-- TODO: clean up this if statement
if type(msg) == "boolean" or #msg == 0 then
return "LSP Inactive"
end
return msg
end
-- add client
for _, client in pairs(buf_clients) do
if client.name ~= "null-ls" and client.name ~= "copilot" then
table.insert(buf_client_names, client.name)
end
end
-- add formatter
local supported_formatters = formatter.list_registered(buf_ft)
vim.list_extend(buf_client_names, supported_formatters)
-- add linter
local supported_linters = linter.linter_list_registered(buf_ft)
vim.list_extend(buf_client_names, supported_linters)
-- decomple
-- local unique_client_names = vim.fn.uniq(buf_client_names)
local unique_client_names = unique_list(buf_client_names)
msg = table.concat(unique_client_names, ", ")
return msg
end,
icon = icons.ui.Gear .. "",
padding = 1,
cond = hide_in_width,
},
-- diagnostics info
diagnostics = {
"diagnostics",
sources = { "nvim_diagnostic" },
sections = { "error", "warn" },
symbols = {
error = icons.diagnostics.BoldError .. " ",
warn = icons.diagnostics.BoldWarning .. " ",
},
colored = true,
update_in_insert = false,
always_visible = false,
},
-- git info
diff = {
"diff",
colored = true,
symbols = {
added = icons.git.LineAdded .. " ",
modified = icons.git.LineModified .. " ",
removed = icons.git.LineRemoved .. " ",
},
cond = hide_in_width,
},
-- tab info
spaces = {
function()
-- local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
-- local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { scope = "buf", bufnr = 0 })
local shiftwidth = vim.fn.shiftwidth()
return icons.ui.Tab .. " " .. shiftwidth
end,
padding = 1,
},
-- nvim mode info
mode_rounded = {
"mode",
padding = 1,
separator = { left = "" },
fmt = function(str)
2024-05-29 16:15:20 +07:00
if vim.g.pcode_show_mode == 1 then
return icons.ui.Neovim .. " " .. (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 2 then
return icons.ui.Neovim
elseif vim.g.pcode_show_mode == 3 then
return (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 4 then
return nil
else
return icons.ui.Neovim .. " " .. str
end
2024-05-22 20:42:09 +07:00
end,
},
2024-05-23 14:15:21 +07:00
mode_roundedall = {
"mode",
padding = 1,
separator = { left = "", right = "" },
fmt = function(str)
2024-05-29 16:15:20 +07:00
if vim.g.pcode_show_mode == 1 then
return icons.ui.Neovim .. " " .. (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 2 then
return icons.ui.Neovim
elseif vim.g.pcode_show_mode == 3 then
return (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 4 then
return nil
else
return icons.ui.Neovim .. " " .. str
end
2024-05-23 14:15:21 +07:00
end,
},
mode_triangle = {
"mode",
padding = 1,
separator = { left = " ", right = "" },
fmt = function(str)
2024-05-29 16:15:20 +07:00
if vim.g.pcode_show_mode == 1 then
return icons.ui.Neovim .. " " .. (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 2 then
return icons.ui.Neovim
elseif vim.g.pcode_show_mode == 3 then
return (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 4 then
return nil
else
return icons.ui.Neovim .. " " .. str
end
2024-05-23 14:15:21 +07:00
end,
},
2024-05-23 18:08:15 +07:00
mode_parallelogram = {
"mode",
padding = 1,
2024-05-23 21:02:23 +07:00
separator = { left = "", right = "" },
2024-05-23 18:08:15 +07:00
fmt = function(str)
2024-05-29 16:15:20 +07:00
if vim.g.pcode_show_mode == 1 then
return icons.ui.Neovim .. " " .. (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 2 then
return icons.ui.Neovim
elseif vim.g.pcode_show_mode == 3 then
return (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 4 then
return nil
else
return icons.ui.Neovim .. " " .. str
end
2024-05-23 18:08:15 +07:00
end,
},
2024-05-22 20:42:09 +07:00
mode_square = {
"mode",
padding = 1,
2024-05-23 18:08:15 +07:00
separator = { left = " " },
2024-05-22 20:42:09 +07:00
fmt = function(str)
2024-05-29 16:15:20 +07:00
if vim.g.pcode_show_mode == 1 then
return icons.ui.Neovim .. " " .. (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 2 then
return icons.ui.Neovim
elseif vim.g.pcode_show_mode == 3 then
return (mode_map[str] or str)
elseif vim.g.pcode_show_mode == 4 then
return nil
else
return icons.ui.Neovim .. " " .. str
end
2024-05-22 20:42:09 +07:00
end,
},
2024-05-23 21:29:02 +07:00
path = {
"filename",
file_status = true,
path = 1,
fmt = function(str)
return "[" .. str .. "]"
end,
cond = hide_in_width,
},
2024-05-22 20:42:09 +07:00
-- git branch info
get_branch = function()
if vim.b.gitsigns_head ~= nil then
2024-05-29 21:01:36 +07:00
return icons.git.Branch3 .. " " .. getLeftSubstring(vim.b.gitsigns_head, 6)
2024-05-22 20:42:09 +07:00
else
2024-05-29 20:48:09 +07:00
return icons.git.NoBranch .. vim.fn.fnamemodify("", ":t")
2024-05-22 20:42:09 +07:00
end
end,
-- default colorscheme
colors = {
blue = "#50fa7b",
cyan = "#f1fa8c",
black = "#1a1b26",
black_transparant = "none",
white = "#c6c6c6",
red = "#ff757f",
skyblue_1 = "#bd93f9",
grey = "#5f6a8e",
yellow = "#ffb86c",
fg_gutter = "#3b4261",
green1 = "#bd93f9",
},
-- default lualine theme
bubbles_theme = function(colors)
return {
normal = {
a = { fg = colors.black, bg = colors.skyblue_1 },
b = { fg = colors.white, bg = colors.grey },
c = { fg = colors.white, bg = colors.black_transparant },
},
insert = {
a = { fg = colors.black, bg = colors.blue },
b = { fg = colors.blue, bg = colors.grey },
},
visual = {
a = { fg = colors.black, bg = colors.cyan },
b = { fg = colors.cyan, bg = colors.grey },
},
replace = {
a = { bg = colors.red, fg = colors.black },
b = { bg = colors.fg_gutter, fg = colors.red },
},
command = {
a = { bg = colors.yellow, fg = colors.black },
b = { bg = colors.fg_gutter, fg = colors.yellow },
},
terminal = {
a = { bg = colors.green1, fg = colors.black },
b = { bg = colors.fg_gutter, fg = colors.green1 },
},
inactive = {
a = { fg = colors.white, bg = colors.black_transparant },
b = { fg = colors.white, bg = colors.black_transparant },
c = { fg = colors.black, bg = colors.black_transparant },
},
}
end,
2024-05-23 18:08:15 +07:00
transparent = function(colors)
return {
normal = {
a = { fg = colors.skyblue_1, bg = colors.black_transparant },
b = { fg = colors.white, bg = colors.black_transparant },
c = { fg = colors.white, bg = colors.black_transparant },
},
insert = {
a = { fg = colors.blue, bg = colors.black_transparant },
b = { fg = colors.white, bg = colors.black_transparant },
},
visual = {
a = { fg = colors.cyan, bg = colors.black_transparant },
b = { fg = colors.white, bg = colors.black_transparant },
},
replace = {
a = { bg = colors.black_transparant, fg = colors.red },
b = { bg = colors.black_transparant, fg = colors.white },
},
command = {
a = { bg = colors.black_transparant, fg = colors.yellow },
b = { bg = colors.black_transparant, fg = colors.white },
},
terminal = {
a = { bg = colors.black_transparant, fg = colors.green1 },
b = { bg = colors.black_transparant, fg = colors.white },
},
inactive = {
a = { fg = colors.white, bg = colors.black_transparant },
b = { fg = colors.white, bg = colors.black_transparant },
c = { fg = colors.black, bg = colors.black_transparant },
},
}
end,
2024-05-21 08:33:21 +07:00
}