317 lines
9.4 KiB
Lua
317 lines
9.4 KiB
Lua
return {
|
|
"nvim-lualine/lualine.nvim",
|
|
config = function()
|
|
-- Eviline config for lualine
|
|
-- Author: shadmansaleh
|
|
-- Credit: glepnir
|
|
local lualine = require("lualine")
|
|
local ctp = require("catppuccin.palettes").get_palette("macchiato")
|
|
|
|
-- Utility to blend two hex colors: result = (1 - alpha) * a + alpha * b
|
|
local function blend_hex(hex_a, hex_b, alpha)
|
|
local function hex_to_rgb(h)
|
|
h = h:gsub("#", "")
|
|
return tonumber(h:sub(1, 2), 16), tonumber(h:sub(3, 4), 16), tonumber(h:sub(5, 6), 16)
|
|
end
|
|
local function rgb_to_hex(r, g, b)
|
|
return string.format("#%02x%02x%02x", math.floor(r + 0.5), math.floor(g + 0.5), math.floor(b + 0.5))
|
|
end
|
|
local ar, ag, ab = hex_to_rgb(hex_a)
|
|
local br, bg, bb = hex_to_rgb(hex_b)
|
|
local r = ar * (1 - alpha) + br * alpha
|
|
local g = ag * (1 - alpha) + bg * alpha
|
|
local b = ab * (1 - alpha) + bb * alpha
|
|
return rgb_to_hex(r, g, b)
|
|
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,
|
|
}
|
|
|
|
-- Config
|
|
local config = {
|
|
options = {
|
|
component_separators = "",
|
|
section_separators = "",
|
|
theme = {
|
|
normal = { c = { fg = ctp.text, bg = "NONE" } },
|
|
inactive = { c = { fg = ctp.overlay0, bg = "NONE" } },
|
|
},
|
|
},
|
|
sections = {
|
|
-- these are to remove the defaults
|
|
lualine_a = {},
|
|
lualine_b = {},
|
|
lualine_y = {},
|
|
lualine_z = {},
|
|
-- These will be filled later
|
|
lualine_c = {},
|
|
lualine_x = {},
|
|
},
|
|
inactive_sections = {
|
|
-- these are to remove the defaults
|
|
lualine_a = {},
|
|
lualine_b = {},
|
|
lualine_y = {},
|
|
lualine_z = {},
|
|
lualine_c = {},
|
|
lualine_x = {},
|
|
},
|
|
}
|
|
|
|
-- Function to get abbreviated mode indicators for status line
|
|
-- Returns a single character representing the current mode
|
|
-- Usage example: local mode = get_mode_abbr()
|
|
local function get_mode_abbr()
|
|
local mode_map = {
|
|
["n"] = "N", -- Normal
|
|
["no"] = "N", -- Operator-pending
|
|
["nov"] = "N", -- Operator-pending (forced charwise)
|
|
["noV"] = "N", -- Operator-pending (forced linewise)
|
|
["no\22"] = "N", -- Operator-pending (forced blockwise)
|
|
["niI"] = "N", -- Normal using i_CTRL-O in Insert-mode
|
|
["niR"] = "N", -- Normal using i_CTRL-O in Replace-mode
|
|
["niV"] = "N", -- Normal using i_CTRL-O in Virtual-Replace-mode
|
|
["nt"] = "N", -- Normal in terminal-emulator
|
|
["v"] = "V", -- Visual
|
|
["vs"] = "V", -- Visual using i_CTRL-O in Select-mode
|
|
["V"] = "VL", -- Visual Line
|
|
["Vs"] = "VL", -- Visual Line using i_CTRL-O in Select-mode
|
|
["\22"] = "VB", -- Visual Block
|
|
["\22s"] = "VB", -- Visual Block using i_CTRL-O in Select-mode
|
|
["s"] = "S", -- Select
|
|
["S"] = "SL", -- Select Line
|
|
["\19"] = "SB", -- Select Block
|
|
["i"] = "I", -- Insert
|
|
["ic"] = "I", -- Insert mode completion
|
|
["ix"] = "I", -- Insert mode i_CTRL-X
|
|
["R"] = "R", -- Replace
|
|
["Rc"] = "R", -- Replace mode completion
|
|
["Rx"] = "R", -- Replace mode i_CTRL-X
|
|
["Rv"] = "VR", -- Virtual Replace
|
|
["Rvc"] = "VR", -- Virtual Replace mode completion
|
|
["Rvx"] = "VR", -- Virtual Replace mode i_CTRL-X
|
|
["c"] = "C", -- Command-line
|
|
["cv"] = "EX", -- Vim Ex mode
|
|
["ce"] = "EX", -- Normal Ex mode
|
|
["r"] = "P", -- Prompt
|
|
["rm"] = "M", -- More prompt
|
|
["r?"] = "C", -- Confirm
|
|
["!"] = "S", -- Shell
|
|
["t"] = "T", -- Terminal
|
|
}
|
|
|
|
local current_mode = vim.api.nvim_get_mode().mode
|
|
return mode_map[current_mode] or current_mode
|
|
end
|
|
|
|
-- Function to get Catppuccin color for the current mode
|
|
-- Returns the appropriate color from the ctp palette based on current mode
|
|
-- Assumes that a local 'ctp' variable has already been defined
|
|
-- Usage example: local mode_color = get_mode_color()
|
|
local function get_mode_color()
|
|
local mode_colors = {
|
|
-- Normal mode - Blue
|
|
["n"] = ctp.blue,
|
|
["no"] = ctp.blue,
|
|
["nov"] = ctp.blue,
|
|
["noV"] = ctp.blue,
|
|
["no\22"] = ctp.blue,
|
|
["niI"] = ctp.green,
|
|
["niR"] = ctp.green,
|
|
["niV"] = ctp.green,
|
|
["nt"] = ctp.blue,
|
|
|
|
-- Visual modes - Mauve (purple)
|
|
["v"] = ctp.mauve,
|
|
["vs"] = ctp.mauve,
|
|
["V"] = ctp.mauve,
|
|
["Vs"] = ctp.mauve,
|
|
["\22"] = ctp.mauve,
|
|
["\22s"] = ctp.mauve,
|
|
|
|
-- Select modes - Peach
|
|
["s"] = ctp.peach,
|
|
["S"] = ctp.peach,
|
|
["\19"] = ctp.peach,
|
|
|
|
-- Insert mode - Green
|
|
["i"] = ctp.green,
|
|
["ic"] = ctp.green,
|
|
["ix"] = ctp.green,
|
|
|
|
-- Replace modes - Red
|
|
["R"] = ctp.red,
|
|
["Rc"] = ctp.red,
|
|
["Rx"] = ctp.red,
|
|
["Rv"] = ctp.red,
|
|
["Rvc"] = ctp.red,
|
|
["Rvx"] = ctp.red,
|
|
|
|
-- Command/Prompt modes - Yellow
|
|
["c"] = ctp.yellow,
|
|
["cv"] = ctp.yellow,
|
|
["ce"] = ctp.yellow,
|
|
["r"] = ctp.yellow,
|
|
["rm"] = ctp.yellow,
|
|
["r?"] = ctp.yellow,
|
|
|
|
-- Terminal mode - Teal
|
|
["t"] = ctp.teal,
|
|
|
|
-- Shell mode - Sapphire
|
|
["!"] = ctp.sapphire,
|
|
}
|
|
|
|
local current_mode = vim.api.nvim_get_mode().mode
|
|
return mode_colors[current_mode] or ctp.subtext0 -- Default to a neutral color if mode not found
|
|
end
|
|
|
|
-- Human-readable mode labels
|
|
local function get_mode_label()
|
|
local m = vim.api.nvim_get_mode().mode
|
|
local normal = {
|
|
n = true,
|
|
no = true,
|
|
nov = true,
|
|
["noV"] = true,
|
|
["no\22"] = true,
|
|
niI = true,
|
|
niR = true,
|
|
niV = true,
|
|
nt = true,
|
|
}
|
|
if normal[m] then
|
|
return "NORM"
|
|
end
|
|
if m == "i" or m == "ic" or m == "ix" then
|
|
return "INS"
|
|
end
|
|
if m == "v" or m == "V" or m == "\22" or m == "vs" or m == "Vs" or m == "\22s" then
|
|
return "VIS"
|
|
end
|
|
if m == "R" or m == "Rc" or m == "Rx" or m == "Rv" or m == "Rvc" or m == "Rvx" then
|
|
return "REPL"
|
|
end
|
|
if m == "c" or m == "cv" or m == "ce" then
|
|
return "CMD"
|
|
end
|
|
if m == "t" or m == "!" then
|
|
return "TERM"
|
|
end
|
|
return "?"
|
|
end
|
|
|
|
-- Inserts a component in lualine_c at left section
|
|
local function ins_left(component)
|
|
table.insert(config.sections.lualine_c, component)
|
|
end
|
|
|
|
-- Inserts a component in lualine_x at right section
|
|
local function ins_right(component)
|
|
table.insert(config.sections.lualine_x, component)
|
|
end
|
|
|
|
ins_left({
|
|
function()
|
|
return get_mode_label()
|
|
end,
|
|
color = function()
|
|
local mode_color = get_mode_color()
|
|
local mode_bg = blend_hex(ctp.base, mode_color, 0.254)
|
|
return { fg = mode_color, bg = mode_bg, gui = "bold" }
|
|
end,
|
|
padding = { left = 1, right = 1 },
|
|
})
|
|
|
|
ins_left({
|
|
"filename",
|
|
cond = conditions.buffer_not_empty,
|
|
color = { fg = ctp.subtext0 },
|
|
})
|
|
|
|
-- visual separation using color only, no ASCII separators
|
|
ins_left({ "location", color = { fg = ctp.overlay1 } })
|
|
|
|
ins_left({
|
|
"diagnostics",
|
|
sources = { "nvim_diagnostic" },
|
|
symbols = { error = "", warn = "", info = "" },
|
|
diagnostics_color = {
|
|
error = { fg = ctp.red },
|
|
warn = { fg = ctp.yellow },
|
|
info = { fg = ctp.teal },
|
|
},
|
|
})
|
|
|
|
-- 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,
|
|
})
|
|
|
|
-- LSP client indicator (badge)
|
|
ins_right({
|
|
function()
|
|
local buf_ft = vim.api.nvim_get_option_value("filetype", { buf = 0 })
|
|
local clients = vim.lsp.get_clients()
|
|
if next(clients) == nil then
|
|
return ""
|
|
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 ""
|
|
end,
|
|
color = function()
|
|
return { fg = ctp.sapphire, bg = blend_hex(ctp.base, ctp.sapphire, 0.254), gui = "bold" }
|
|
end,
|
|
padding = { left = 1, right = 1 },
|
|
})
|
|
|
|
-- CMP badge (visible in insert mode)
|
|
ins_right({
|
|
function()
|
|
return "CMP"
|
|
end,
|
|
cond = function()
|
|
local mode = vim.api.nvim_get_mode().mode
|
|
return mode == "i" or mode == "ic" or mode == "ix"
|
|
end,
|
|
color = { fg = ctp.base, bg = ctp.teal },
|
|
padding = { left = 1, right = 1 },
|
|
})
|
|
|
|
-- Language/filetype badge
|
|
ins_right({
|
|
"filetype",
|
|
colored = false,
|
|
icon_only = false,
|
|
color = function()
|
|
return { fg = ctp.text, ctp.surface0, gui = "bold" }
|
|
end,
|
|
padding = { left = 1, right = 1 },
|
|
})
|
|
|
|
-- Minimal right side
|
|
ins_right({ "progress", color = { fg = ctp.overlay1 } })
|
|
|
|
-- Now don't forget to initialize lualine
|
|
lualine.setup(config)
|
|
end,
|
|
}
|