refractor(nvim): Refractor lualine.nvim

This commit is contained in:
js0ny 2025-01-26 20:47:38 +00:00
parent a5218cdea7
commit 21a77b4524
11 changed files with 231 additions and 208 deletions

View file

@ -41,25 +41,6 @@ return {
})
end,
},
{
"nvim-orgmode/orgmode",
event = "VeryLazy",
ft = { "org" },
config = function()
-- Setup orgmode
require("orgmode").setup({
org_agenda_files = "~/orgfiles/**/*",
org_default_notes_file = "~/orgfiles/refile.org",
})
-- NOTE: If you are using nvim-treesitter with ~ensure_installed = "all"~ option
-- add ~org~ to ignore_install
-- require('nvim-treesitter.configs').setup({
-- ensure_installed = 'all',
-- ignore_install = { 'org' },
-- })
end,
},
{ import = "plugins.mod.conform-nvim" },
{ "nvim-treesitter/nvim-treesitter-context" },
{

View file

@ -0,0 +1,168 @@
local M = {}
local colors = require("config.colors")
local icons = require("config.icons")
local function diff_source()
local gitsigns = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitsigns.added,
modified = gitsigns.changed,
removed = gitsigns.removed,
}
end
end
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand("%:p:h")
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local mode_color = {
n = colors.blue,
i = colors.green,
v = colors.magenta,
[""] = colors.magenta,
V = colors.magenta,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
[""] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
["r?"] = colors.cyan,
["!"] = colors.red,
t = colors.red,
}
local mode_color_bg = function()
return { fg = colors.bg, bg = mode_color[vim.fn.mode()] }
end
-- local mode_color_fg = function()
-- return { fg = mode_color[vim.fn.mode()] }
-- end
M.mode = {
function()
return ""
end,
color = mode_color_bg,
}
M.git = {
"branch",
icon = icons.git.Branch,
color = { fg = colors.violet, gui = "bold" },
}
M.diagnostics = {
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = {
error = icons.diagnostics.Error .. " ",
warn = icons.diagnostics.Warning .. " ",
info = icons.diagnostics.Information .. " ",
hint = icons.diagnostics.Hint .. " ",
},
}
M.lsp = {
-- Lsp server name .
function()
local msg = "LSP Inactive"
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end,
icon = icons.lsp,
color = { fg = colors.yellow, gui = "italic" },
}
M.filetype = {
function()
return vim.bo.filetype
end,
color = { fg = colors.blue, gui = "bold" },
}
M.eol = {
function()
return vim.bo.eol == true and icons.eol or ""
end,
color = { fg = colors.red },
}
M.command = {
"command",
color = { fg = colors.green, gui = "bold" },
}
M.encoding = {
"o:encoding",
color = { fg = colors.green, gui = "bold" },
}
M.indent = {
function()
local shiftwidth = vim.api.nvim_get_option_value("shiftwidth", { buf = 0 })
return icons.indent .. " " .. shiftwidth
end,
padding = 1,
}
-- M.diff = {
-- "diff",
-- -- Is it me or the symbol for modified us really weird
-- symbols = { added = " ", modified = "󰝤 ", removed = " " },
-- diff_color = {
-- added = { fg = colors.green },
-- modified = { fg = colors.orange },
-- removed = { fg = colors.red },
-- },
-- cond = conditions.hide_in_width,
-- }
M.diff = {
"diff",
source = diff_source,
-- symbols = { added = " ", modified = "󰝤 ", removed = " " },
symbols = {
added = icons.git.Add .. " ",
modified = icons.git.Change .. " ",
removed = icons.git.Delete .. " ",
},
padding = { left = 2, right = 1 },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.yellow },
removed = { fg = colors.red },
},
cond = nil,
}
M.progress = { "progress", color = mode_color_bg }
return M

View file

@ -1,34 +1,9 @@
local lualine = require("lualine")
-- Color table for highlights
-- stylua: ignore
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand("%:t")) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand("%:p:h")
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local colors = require("plugins.mod.lualine.colors")
local components = require("plugins.mod.lualine.components")
-- Config
local config = {
@ -78,157 +53,21 @@ local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left({
function()
return ""
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
})
--[[
VSCode Style:
Remote | Git Branch | Diagnostics | Command | | MID | | Line:Column | Indent | Encoding | EOL | File Type LSP | Notifications
--]]
ins_left({
-- mode component
function()
return ""
end,
color = function()
-- auto change color according to neovims mode
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.blue,
[""] = colors.blue,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
[""] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
["r?"] = colors.cyan,
["!"] = colors.red,
t = colors.red,
}
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { right = 1 },
})
ins_left(components.mode)
ins_left(components.diff)
ins_left(components.git)
ins_left(components.diagnostics)
ins_left(components.command)
ins_right(components.indent)
ins_right(components.encoding)
ins_right(components.eol)
ins_right(components.filetype)
ins_right(components.lsp)
ins_right(components.progress)
-- ins_left {
-- -- filesize component
-- 'filesize',
-- cond = conditions.buffer_not_empty,
-- }
-- ins_left {
-- 'filename',
-- cond = conditions.buffer_not_empty,
-- color = { fg = colors.magenta, gui = 'bold' },
-- }
-- ins_left { 'location' }
ins_right({ "progress", color = { fg = colors.fg, gui = "bold" } })
ins_left({
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = { error = "", warn = "", info = "" },
diagnostics_color = {
error = { fg = colors.red },
warn = { fg = colors.yellow },
info = { fg = colors.cyan },
},
})
ins_left({
function()
return vim.bo.filetype
end,
color = { fg = colors.blue, gui = "bold" },
})
ins_left({
function()
return vim.bo.shiftwidth .. " space"
end,
})
ins_left({
-- Lsp server name .
function()
local msg = "No Active Lsp"
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end,
icon = "",
color = { fg = "#ffffff", gui = "bold" },
})
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left({
function()
return "%="
end,
})
-- Add components to right sections
ins_right({
"o:encoding", -- option component same as &encoding in viml
fmt = string.upper, -- I'm not sure why it's upper case either ;)
cond = conditions.hide_in_width,
color = { fg = colors.green, gui = "bold" },
})
ins_right({
"fileformat",
fmt = string.upper,
icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
color = { fg = colors.green, gui = "bold" },
})
ins_right({
"branch",
icon = "",
color = { fg = colors.violet, gui = "bold" },
})
ins_right({
"diff",
-- Is it me or the symbol for modified us really weird
symbols = { added = "", modified = "󰝤 ", removed = "" },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
})
ins_right({
function()
return ""
end,
color = { fg = colors.blue },
padding = { left = 1 },
})
-- Now don't forget to initialize lualine
lualine.setup(config)