Skip to content

Commit 68d9fdd

Browse files
mode bg capsule fix
1 parent 6da7eb5 commit 68d9fdd

File tree

4 files changed

+53
-44
lines changed

4 files changed

+53
-44
lines changed

nvim/lua/dko/heirline/mode.lua

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local utils = require("heirline.utils")
2+
13
-- Now we define some dictionaries to map the output of mode() to the
24
-- corresponding string and color. We can put these into `static` to compute
35
-- them at initialisation time.
@@ -51,6 +53,25 @@ local mode_colors = {
5153
t = "red",
5254
}
5355

56+
local function mode_hl()
57+
local mode = vim.fn.mode(1):sub(1, 1):lower() -- get only the first mode character
58+
59+
-- My hardcoded settings
60+
if mode == "n" then
61+
return "StatusLine"
62+
elseif mode == "c" then
63+
return "DiffDelete"
64+
elseif mode == "i" then
65+
return "dkoStatusItem"
66+
elseif mode == "r" then
67+
return "dkoLineModeReplace"
68+
elseif mode == "v" then
69+
return "Cursor"
70+
end
71+
72+
return { fg = mode_colors[mode] }
73+
end
74+
5475
return {
5576
-- get vim current mode, this information will be required by the provider
5677
-- and the highlight functions, so we compute it only once per component
@@ -69,32 +90,25 @@ return {
6990
end
7091
end,
7192

72-
provider = function(self)
73-
return mode_names[self.mode]
74-
end,
75-
76-
-- Same goes for the highlight. Now the foreground will change according to the current mode.
77-
hl = function(self)
78-
local mode = self.mode:sub(1, 1):lower() -- get only the first mode character
79-
80-
-- My hardcoded settings
81-
if mode == "n" then
82-
return "StatusLine"
83-
elseif mode == "c" then
84-
return "DiffDelete"
85-
elseif mode == "i" then
86-
return "dkoStatusItem"
87-
elseif mode == "r" then
88-
return "dkoLineModeReplace"
89-
elseif mode == "v" then
90-
return "Cursor"
93+
utils.surround({ "", "" }, function()
94+
local hl = mode_hl()
95+
if type(hl) == "string" then
96+
return utils.get_highlight(hl).bg
9197
end
98+
return utils.get_highlight("StatusLine").bg
99+
end, {
100+
provider = function(self)
101+
return mode_names[self.mode]
102+
end,
92103

93-
return { fg = mode_colors[mode] }
94-
end,
104+
-- Same goes for the highlight. Now the foreground will change according to the current mode.
105+
hl = function()
106+
return mode_hl()
107+
end,
95108

96-
-- Re-evaluate the component only on ModeChanged event!
97-
-- This is not required in any way, but it's there, and it's a small
98-
-- performance improvement.
99-
update = { "ModeChanged", "TermLeave" },
109+
-- Re-evaluate the component only on ModeChanged event!
110+
-- This is not required in any way, but it's there, and it's a small
111+
-- performance improvement.
112+
update = { "ModeChanged", "TermLeave" },
113+
}),
100114
}

nvim/lua/dko/heirline/ruler.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local utils = require("heirline.utils")
2+
3+
return {
4+
condition = require("heirline.conditions").is_active,
5+
utils.surround({ "", "" }, function()
6+
return utils.get_highlight("StatusLine").bg
7+
end, {
8+
provider = "%5.(%c%)",
9+
hl = "StatusLine",
10+
}),
11+
}
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
local utils = require("heirline.utils")
2-
31
return {
4-
utils.surround({ "", "" }, function()
5-
return utils.get_highlight("StatusLine").bg
6-
end, {
7-
require("dko.heirline.mode"),
8-
}),
9-
2+
require("dko.heirline.mode"),
103
require("dko.heirline.searchterm"),
114

125
-- this means that the statusline is cut here when there's not enough space
@@ -18,14 +11,5 @@ return {
1811
hl = "StatusLineNC",
1912
},
2013

21-
-- ruler
22-
{
23-
condition = require("heirline.conditions").is_active,
24-
utils.surround({ "", "" }, function()
25-
return utils.get_highlight("StatusLine").bg
26-
end, {
27-
provider = "%5.(%c%)",
28-
hl = "StatusLine",
29-
}),
30-
},
14+
require("dko.heirline.ruler"),
3115
}

nvim/lua/dko/heirline/winbar-filetype.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ return {
2424
}
2525
end,
2626

27-
utils.surround({ "", "" }, function()
27+
utils.surround({ "", "" }, function()
2828
local bg = dkots.is_highlight_enabled()
2929
and utils.get_highlight("dkoStatusKey").bg
3030
or utils.get_highlight("DiffDelete").bg

0 commit comments

Comments
 (0)