Skip to content

Commit 2c404ef

Browse files
authored
Merge pull request #45 from nikero41/statusline-revamp
Statusline revamp
2 parents 38bfca6 + cb05410 commit 2c404ef

12 files changed

Lines changed: 288 additions & 214 deletions

File tree

lua/highlights.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function Highlights:get()
3434
local colors = require("catppuccin.palettes").get_palette("mocha")
3535
local cursor_line_bg = helpers:blend(colors.mauve, "#000000", 0.28)
3636

37+
---@type table<string, vim.api.keyset.highlight>
3738
local highlights = {
3839
Visual = { bg = helpers:blend(colors.mauve, "#000000", 0.4) },
3940
CursorLine = { bg = cursor_line_bg },
@@ -55,6 +56,10 @@ function Highlights:get()
5556
NavicText = { link = "lualine_c_inactive" },
5657
NavicSeparator = { link = "lualine_c_inactive" },
5758

59+
-- Statusline
60+
OverlayActive = { bg = colors.surface1 },
61+
OverlayActiveInverted = { fg = colors.surface1 },
62+
5863
-- LSP
5964
LspReferenceText = { underline = true },
6065
["@tag.builtin"] = { link = "Special" },

lua/keymaps.lua

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,33 @@ keymaps:add_multiple({
122122
{
123123
"n",
124124
"[e",
125-
function() vim.diagnostic.jump({ count = -vim.v.count1, severity = "ERROR" }) end,
125+
function()
126+
vim.diagnostic.jump({ count = -vim.v.count1, severity = vim.diagnostic.severity.ERROR })
127+
end,
126128
{ desc = "Previous error" },
127129
},
128130
{
129131
"n",
130132
"]e",
131-
function() vim.diagnostic.jump({ count = vim.v.count1, severity = "ERROR" }) end,
133+
function()
134+
vim.diagnostic.jump({ count = vim.v.count1, severity = vim.diagnostic.severity.ERROR })
135+
end,
132136
{ desc = "Next error" },
133137
},
134138
{
135139
"n",
136140
"[w",
137-
function() vim.diagnostic.jump({ count = -vim.v.count1, severity = "WARN" }) end,
141+
function()
142+
vim.diagnostic.jump({ count = -vim.v.count1, severity = vim.diagnostic.severity.WARN })
143+
end,
138144
{ desc = "Previous warning" },
139145
},
140146
{
141147
"n",
142148
"]w",
143-
function() vim.diagnostic.jump({ count = vim.v.count1, severity = "WARN" }) end,
149+
function()
150+
vim.diagnostic.jump({ count = vim.v.count1, severity = vim.diagnostic.severity.WARN })
151+
end,
144152
{ desc = "Next warning" },
145153
},
146154
})
@@ -198,7 +206,16 @@ keymaps:add_multiple({
198206
{
199207
"n",
200208
"<leader>lr",
201-
function() vim.lsp.buf.rename() end,
209+
function()
210+
vim.lsp.buf.rename(nil, {
211+
---@type snacks.input.Config
212+
snacks = {
213+
win = {
214+
relative = "cursor",
215+
},
216+
},
217+
})
218+
end,
202219
{ desc = "Rename current symbol", lsp = { method = "textDocument/rename" } },
203220
},
204221
{

lua/nikero/lualine.lua

Lines changed: 0 additions & 20 deletions
This file was deleted.

lua/nikero/statusline.lua

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---@class StatusLine
2+
---@field statusline_icon_hl fun(self: StatusLine, icon_hl: string, default_hl_token: string): string
3+
local StatusLine = {}
4+
5+
function StatusLine:statusline_icon_hl(icon_hl, default_hl_token)
6+
local base_hl = default_hl_token:match("%%#(.-)#") or default_hl_token
7+
local group = ("Nikero_%s_%s"):format(base_hl, icon_hl):gsub("[^%w_]", "_")
8+
local icon = vim.api.nvim_get_hl(0, { name = group, link = false })
9+
10+
if next(icon) ~= nil then return group end
11+
12+
local base = vim.api.nvim_get_hl(0, { name = base_hl, link = false })
13+
local new_icon = vim.api.nvim_get_hl(0, { name = icon_hl, link = false })
14+
15+
vim.api.nvim_set_hl(0, group, { fg = new_icon.fg, bg = base.bg })
16+
17+
return group
18+
end
19+
20+
function StatusLine:harpoon_item(default_hl, active_index)
21+
return function(index, item)
22+
local file_path = vim.fn.fnamemodify(item.value, ":p")
23+
local icon, base_icon_hl = require("mini.icons").get("file", file_path)
24+
25+
local is_active = index == active_index
26+
local base_hl = default_hl
27+
if is_active then base_hl = "%#OverlayActive#" end
28+
29+
local icon_hl = self:statusline_icon_hl(base_icon_hl, base_hl)
30+
local icon_str = self:wrap(icon_hl, icon) .. base_hl
31+
32+
local value = string.format("%s %d", icon_str, index)
33+
34+
if is_active then
35+
local side_hl = self:statusline_icon_hl("OverlayActiveInverted", default_hl)
36+
value = self:wrap(side_hl, "") .. value .. self:wrap(side_hl, "") .. default_hl
37+
else
38+
value = string.format(" %s ", value)
39+
end
40+
41+
return value
42+
end
43+
end
44+
45+
local MAX_DISPLAYED_WIDGETS = 3
46+
47+
function StatusLine:harpoon_widget(default_hl)
48+
local current_file = vim.fn.expand("%:p")
49+
local items = require("harpoon"):list().items
50+
51+
local active_index = vim.iter(ipairs(items)):find(
52+
function(_, item) return vim.fn.fnamemodify(item.value, ":p") == current_file end
53+
)
54+
55+
local start_index = 1
56+
if
57+
#items > MAX_DISPLAYED_WIDGETS
58+
and active_index ~= nil
59+
and active_index >= MAX_DISPLAYED_WIDGETS - 1
60+
then
61+
start_index = math.max(math.min(active_index - 1, #items - MAX_DISPLAYED_WIDGETS + 1), 0)
62+
end
63+
64+
local widgets = vim
65+
.iter(ipairs(items))
66+
:skip(start_index - 1)
67+
:take(MAX_DISPLAYED_WIDGETS)
68+
:map(self:harpoon_item(default_hl, active_index))
69+
:join("")
70+
71+
if start_index ~= 1 then widgets = string.gsub(widgets, "^%s", "<") end
72+
if #items > MAX_DISPLAYED_WIDGETS and start_index ~= #items - MAX_DISPLAYED_WIDGETS + 1 then
73+
widgets = string.gsub(widgets, "%s$", ">")
74+
end
75+
76+
return widgets
77+
end
78+
79+
function StatusLine:wrap(hl, text) return "%#" .. hl .. "#" .. text end
80+
81+
return StatusLine

lua/options.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ vim.diagnostic.config({
8888
jump = {
8989
on_jump = function(diagnostic, buffer)
9090
if not diagnostic then return end
91-
vim.diagnostic.open_float(buffer or 0, { scope = "cursor", focus = false })
91+
vim.diagnostic.open_float({ bufnr = buffer, scope = "cursor", focus = false })
9292
end,
9393
},
9494
float = {

lua/plugins/colorschemes.lua

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,6 @@ return {
121121
opts = {
122122
flavour = "mocha",
123123
auto_integrations = true,
124-
integrations = {
125-
lualine = {
126-
all = function(colors)
127-
return {
128-
normal = {
129-
c = { bg = colors.base, fg = colors.text },
130-
},
131-
inactive = {
132-
a = { bg = colors.base, fg = colors.blue },
133-
b = { bg = colors.base, fg = colors.surface1, gui = "bold" },
134-
c = { bg = colors.base, fg = colors.overlay0 },
135-
},
136-
}
137-
end,
138-
},
139-
},
140124
transparent_background = require("nikero.config").transparency,
141125
dim_inactive = {
142126
enabled = true,

lua/plugins/harpoon.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ return {
1212
end,
1313
desc = "Toggle Harpoon",
1414
},
15-
{
16-
"<leader>ha",
17-
function()
18-
require("harpoon"):list():add()
19-
require("lualine").refresh()
20-
end,
21-
desc = "Add file to Harpoon",
22-
},
15+
{ "<leader>ha", function() require("harpoon"):list():add() end, desc = "Add file to Harpoon" },
2316
{ "<C-p>", function() require("harpoon"):list():prev() end, desc = "Previous Harpoon file" },
2417
{ "<C-n>", function() require("harpoon"):list():next() end, desc = "Next Harpoon file" },
2518
{ "<M-z>", function() require("harpoon"):list():select(1) end, desc = "Goto 1 of mark" },
@@ -36,7 +29,6 @@ return {
3629
:enumerate()
3730
:find(function(_, item) return string.find(buf_name, item.value, 1, true) end)
3831
list:remove_at(index)
39-
require("lualine").refresh()
4032
end,
4133
desc = "Remove current buffer from Harpoon",
4234
},
@@ -78,6 +70,11 @@ return {
7870
{ buf = cx.bufnr }
7971
)
8072
end,
73+
ADD = function() require("lualine").refresh() end,
74+
REMOVE = function() require("lualine").refresh() end,
75+
REORDER = function() require("lualine").refresh() end,
76+
POSITION_UPDATED = function() require("lualine").refresh() end,
77+
LIST_CHANGE = function() require("lualine").refresh() end,
8178
})
8279
end,
8380
}

lua/plugins/language/support.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ return {
2626
end,
2727
},
2828
},
29+
---@module "mason-lspconfig"
2930
---@type MasonLspconfigSettings
3031
opts = {
3132
automatic_enable = {
@@ -49,7 +50,7 @@ return {
4950
"mason-org/mason.nvim",
5051
cmd = { "Mason", "MasonInstall", "MasonUninstall", "MasonUninstallAll", "MasonLog" },
5152
build = ":MasonUpdate",
52-
---@module 'mason'
53+
---@module "mason"
5354
---@type MasonSettings
5455
opts = {
5556
ui = {

0 commit comments

Comments
 (0)