Skip to content

Commit d3c69b9

Browse files
committed
refactor: restructure highlights a little bit better
1 parent 7404d4f commit d3c69b9

File tree

3 files changed

+80
-37
lines changed

3 files changed

+80
-37
lines changed

lua/window-picker/config.lua

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ local config = {
3434
filter_func = nil,
3535

3636
-- following filters are only applied when you are using the default filter
37-
-- defined by this plugin. if you pass in a function to "filter_func"
37+
-- defined by this plugin. If you pass in a function to "filter_func"
3838
-- property, you are on your own
3939
filter_rules = {
4040
-- when there is only one window available to pick from, use that window
@@ -66,16 +66,34 @@ local config = {
6666
file_name_contains = {},
6767
},
6868

69-
-- the foreground (text) color of the picker
70-
fg_color = '#ededed',
71-
72-
-- if you have include_current_win == true, then current_win_hl_color will
73-
-- be highlighted using this background color
74-
current_win_hl_color = '#e35e4f',
75-
76-
-- all the windows except the curren window will be highlighted using this
77-
-- color
78-
other_win_hl_color = '#44cc41',
69+
-- You can pass in the highlight name or a table of content to set as
70+
-- highlight
71+
highlights = {
72+
statusline = {
73+
focused = {
74+
fg = '#ededed',
75+
bg = '#e35e4f',
76+
bold = true,
77+
},
78+
unfocused = {
79+
fg = '#ededed',
80+
bg = '#44cc41',
81+
bold = true,
82+
},
83+
},
84+
winbar = {
85+
focused = {
86+
fg = '#ededed',
87+
bg = '#e35e4f',
88+
bold = true,
89+
},
90+
unfocused = {
91+
fg = '#ededed',
92+
bg = '#44cc41',
93+
bold = true,
94+
},
95+
},
96+
},
7997
}
8098

8199
return config

lua/window-picker/configurer.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function M._basic_config_manipulations(config)
2727
end
2828

2929
function M._backward_compatibility_config_changes(config)
30+
----------------------------------------------------------------------
31+
-- filter rules --
32+
----------------------------------------------------------------------
3033
local filter_rules = config.filter_rules
3134

3235
-- backward compatibility to config.autoselect_one
@@ -39,6 +42,19 @@ function M._backward_compatibility_config_changes(config)
3942
filter_rules.include_current_win = config.include_current_win
4043
end
4144

45+
----------------------------------------------------------------------
46+
-- highlight changes --
47+
----------------------------------------------------------------------
48+
if config.current_win_hl_color then
49+
config.highlights.statusline.focused.bg = config.current_win_hl_color
50+
config.highlights.winbar.focused.bg = config.current_win_hl_color
51+
end
52+
53+
if config.other_win_hl_color then
54+
config.highlights.statusline.unfocused.bg = config.other_win_hl_color
55+
config.highlights.winbar.unfocused.bg = config.other_win_hl_color
56+
end
57+
4258
return config
4359
end
4460

lua/window-picker/hints/statusline-winbar-hint.lua

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,38 @@ function M:set_config(config)
1313
self.use_winbar = config.use_winbar
1414
self.show_prompt = config.show_prompt
1515

16-
vim.api.nvim_set_hl(0, 'WindowPickerStatusLine', {
17-
fg = '#ededed',
18-
bg = config.current_win_hl_color,
19-
bold = true,
20-
})
21-
22-
vim.api.nvim_set_hl(0, 'WindowPickerStatusLineNC', {
23-
fg = '#ededed',
24-
bg = config.other_win_hl_color,
25-
bold = true,
26-
})
27-
28-
vim.api.nvim_set_hl(0, 'WindowPickerWinBar', {
29-
fg = '#ededed',
30-
bg = config.current_win_hl_color,
31-
bold = true,
32-
})
33-
34-
vim.api.nvim_set_hl(0, 'WindowPickerWinBarNC', {
35-
fg = '#ededed',
36-
bg = config.other_win_hl_color,
37-
bold = true,
38-
})
16+
-- registering highlights
17+
if type(config.highlights.statusline.focused) == 'table' then
18+
self.st_hi = 'WindowPickerStatusLine'
19+
vim.api.nvim_set_hl(0, self.st_hi, config.highlights.statusline.focused)
20+
end
21+
22+
if type(config.highlights.statusline.unfocused) == 'table' then
23+
self.st_hi_nc = 'WindowPickerStatusLineNC'
24+
vim.api.nvim_set_hl(
25+
0,
26+
self.st_hi_nc,
27+
config.highlights.statusline.unfocused
28+
)
29+
end
30+
31+
if type(config.highlights.winbar.focused) == 'table' then
32+
self.wb_hi = 'WindowPickerWinBar'
33+
vim.api.nvim_set_hl(
34+
0,
35+
self.wb_hi,
36+
config.highlights.statusline.unfocused
37+
)
38+
end
39+
40+
if type(config.highlights.winbar.unfocused) == 'table' then
41+
self.wb_hi_nc = 'WindowPickerWinBarNC'
42+
vim.api.nvim_set_hl(
43+
0,
44+
self.wb_hi_nc,
45+
config.highlights.statusline.unfocused
46+
)
47+
end
3948
end
4049

4150
--- Shows the characters in status line
@@ -77,11 +86,11 @@ function M:draw(windows)
7786
or '%=' .. char .. '%='
7887

7988
local winhl = string.format(
80-
'%s:WindowPicker%s,%sNC:WindowPicker%sNC',
81-
indicator_hl,
89+
'%s:%s,%sNC:%s',
8290
indicator_hl,
91+
use_winbar and self.wb_hi or self.st_hi,
8392
indicator_hl,
84-
indicator_hl
93+
use_winbar and self.wb_hi_nc or self.wb_hi
8594
)
8695

8796
local ok, result = pcall(

0 commit comments

Comments
 (0)