Skip to content

Commit 94d7d1e

Browse files
committed
feat: add hint specific config properties
1 parent ca789c7 commit 94d7d1e

File tree

6 files changed

+56
-18
lines changed

6 files changed

+56
-18
lines changed

lua/window-picker/config.lua

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@ local config = {
33
-- following letters on them so you can use that letter to select the window
44
selection_chars = 'FJDKSLA;CMRUEIWOQP',
55

6-
-- You can change the display string in status bar.
7-
-- It supports '%' printf style. Such as `return char .. ': %f'` to display
8-
-- buffer filepath. See :h 'stl' for details.
9-
selection_display = function(char, windowid)
10-
return '%=' .. char .. '%='
11-
end,
12-
13-
-- whether you want to use winbar instead of the statusline
14-
-- "always" means to always use winbar,
15-
-- "never" means to never use winbar
16-
-- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0
17-
use_winbar = 'never', -- "always" | "never" | "smart"
6+
-- This section contains picker specific configurations
7+
picker_config = {
8+
statusline_winbar_picker = {
9+
-- You can change the display string in status bar.
10+
-- It supports '%' printf style. Such as `return char .. ': %f'` to display
11+
-- buffer file path. See :h 'stl' for details.
12+
selection_display = function(char, windowid)
13+
return '%=' .. char .. '%='
14+
end,
15+
16+
-- whether you want to use winbar instead of the statusline
17+
-- "always" means to always use winbar,
18+
-- "never" means to never use winbar
19+
-- "smart" means to use winbar if cmdheight=0 and statusline if cmdheight > 0
20+
use_winbar = 'never', -- "always" | "never" | "smart"
21+
},
22+
23+
floating_window_picker = {
24+
-- window picker plugin provides bunch of big letter fonts
25+
-- fonts will be lazy loaded as they are being requested
26+
-- additionally, user can pass in a table of fonts in to font
27+
-- property to use instead
28+
29+
font = 'ansi-shadow', -- ansi-shadow |
30+
},
31+
},
1832

1933
-- whether to show 'Pick window:' prompt
2034
show_prompt = true,

lua/window-picker/configurer.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ function M._backward_compatibility_config_changes(config)
5555
config.highlights.winbar.unfocused.bg = config.other_win_hl_color
5656
end
5757

58+
----------------------------------------------------------------------
59+
-- statusline winbar config --
60+
----------------------------------------------------------------------
61+
if config.selection_display then
62+
config.picker_config.statusline_winbar_picker.selection_display =
63+
config.selection_display
64+
end
65+
66+
if config.use_winbar then
67+
config.picker_config.statusline_winbar_picker.use_winbar =
68+
config.use_winbar
69+
end
70+
5871
return config
5972
end
6073

lua/window-picker/hints/floating-big-letter-hint.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function M:new()
3030
width = 18,
3131
height = 8,
3232
},
33-
windows = {}
33+
windows = {},
3434
}
3535

3636
setmetatable(o, M)
@@ -41,6 +41,15 @@ end
4141

4242
function M:set_config(config)
4343
self.chars = config.chars
44+
local font = config.picker_config.floating_window_picker.font
45+
46+
if type(font) == 'string' then
47+
self.big_chars = require(('window-picker.hints.data.%s'):format(font))
48+
end
49+
50+
if type(font) == 'table' then
51+
self.big_chars = font
52+
end
4453
end
4554

4655
function M:_get_float_win_pos(window)
@@ -116,7 +125,7 @@ end
116125
function M:draw(windows)
117126
for index, window in ipairs(windows) do
118127
local char = self.chars[index]
119-
local big_char = ansi_shadow[char:lower()]
128+
local big_char = self.big_chars[char:lower()]
120129
local window_id = self:_show_letter_in_window(window, big_char)
121130
table.insert(self.windows, window_id)
122131
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ end
2020

2121
function M:set_config(config)
2222
self.chars = config.chars
23-
self.selection_display = config.selection_display
23+
self.selection_display = config.picker_config.statusline_winbar_picker.selection_display
2424

2525
vim.api.nvim_set_hl(0, 'WindowPickerStatusLine', {
2626
fg = '#ededed',

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ local M = StatuslineHint:new()
99

1010
function M:set_config(config)
1111
self.chars = config.chars
12-
self.selection_display = config.selection_display
13-
self.use_winbar = config.use_winbar
1412
self.show_prompt = config.show_prompt
1513

14+
self.selection_display = config.picker_config.statusline_winbar_picker.selection_display
15+
self.use_winbar = config.picker_config.statusline_winbar_picker.use_winbar
16+
1617
-- registering highlights
1718
if type(config.highlights.statusline.focused) == 'table' then
1819
self.st_hi = 'WindowPickerStatusLine'

lua/window-picker/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local FloatingHint = require('window-picker.hints.floating-big-letter-hint')
12
local builder = require('window-picker.builder')
23

34
local M = {}
@@ -6,7 +7,7 @@ function M.pick_window(custom_config)
67
return builder
78
:new()
89
:set_config(custom_config)
9-
:set_hint()
10+
:set_hint(FloatingHint:new())
1011
:set_picker()
1112
:set_filter()
1213
:build()

0 commit comments

Comments
 (0)