Skip to content

Commit 722c2a4

Browse files
committed
feat: add support to big letter float from config
1 parent 94d7d1e commit 722c2a4

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

lua/window-picker/builder.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ function M:set_filter(filter)
3838
end
3939

4040
function M:build()
41-
local config = vim.tbl_deep_extend('force', dconfig, self.config or {})
42-
43-
local configurer = self.configurer or dconfigurer:new(config)
41+
local configurer = self.configurer or dconfigurer:new(self.config)
4442

4543
local hint = configurer:config_hint(self.hint or dhint:new())
4644
local filter = configurer:config_filter(self.filter or dfilter:new())

lua/window-picker/config.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
local config = {
2+
-- type of hints you want to get
3+
-- following types are supported
4+
-- 'statusline-winbar' | 'statusline' | 'floating-big-letter'
5+
hint = 'floating-big-letter',
6+
27
-- when you go to window selection mode, status bar will show one of
38
-- following letters on them so you can use that letter to select the window
49
selection_chars = 'FJDKSLA;CMRUEIWOQP',
@@ -20,7 +25,7 @@ local config = {
2025
use_winbar = 'never', -- "always" | "never" | "smart"
2126
},
2227

23-
floating_window_picker = {
28+
floating_big_letter = {
2429
-- window picker plugin provides bunch of big letter fonts
2530
-- fonts will be lazy loaded as they are being requested
2631
-- additionally, user can pass in a table of fonts in to font

lua/window-picker/configurer.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
local util = require('window-picker.util')
2-
local dconfig = require('window-picker.config')
3-
41
---@class Configurer
52
---@field config any
63
local M = {}
74

85
function M:new(config)
9-
config = config and util.merge_config(dconfig, config) or dconfig
106
config = M._backward_compatibility_config_changes(config)
117
config = M._basic_config_manipulations(config)
128

@@ -15,7 +11,6 @@ function M:new(config)
1511
}
1612

1713
setmetatable(o, self)
18-
1914
self.__index = self
2015

2116
return o

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local ansi_shadow = require('window-picker.hints.data.ansi-shadow')
21
local utf8 = require('window-picker.utf-8')
32

43
--- @class FloatingBigLetterHint
@@ -33,21 +32,21 @@ function M:new()
3332
windows = {},
3433
}
3534

36-
setmetatable(o, M)
35+
setmetatable(o, self)
3736
self.__index = self
3837

3938
return o
4039
end
4140

4241
function M:set_config(config)
4342
self.chars = config.chars
44-
local font = config.picker_config.floating_window_picker.font
43+
local font = config.picker_config.floating_big_letter.font
4544

4645
if type(font) == 'string' then
4746
self.big_chars = require(('window-picker.hints.data.%s'):format(font))
4847
end
4948

50-
if type(font) == 'table' then
49+
if type(font) == 'table' then
5150
self.big_chars = font
5251
end
5352
end

lua/window-picker/init.lua

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1-
local FloatingHint = require('window-picker.hints.floating-big-letter-hint')
21
local builder = require('window-picker.builder')
2+
local dconfig = require('window-picker.config')
33

44
local M = {}
55

66
function M.pick_window(custom_config)
7-
return builder
8-
:new()
9-
:set_config(custom_config)
10-
:set_hint(FloatingHint:new())
11-
:set_picker()
12-
:set_filter()
13-
:build()
14-
:pick_window()
7+
local config = dconfig
8+
9+
-- merge the config
10+
if custom_config then
11+
config = vim.tbl_deep_extend('force', config, custom_config)
12+
end
13+
14+
local hint
15+
16+
if type(config.hint) == 'string' then
17+
local ok, result = pcall(
18+
require,
19+
('window-picker.hints.%s-hint'):format(config.hint)
20+
)
21+
22+
if not ok then
23+
vim.notify(
24+
('No hint found by the name "%s"\nError: %s'):format(
25+
config.hint,
26+
result
27+
),
28+
vim.log.levels.ERROR
29+
)
30+
31+
return
32+
end
33+
34+
hint = result:new()
35+
else
36+
hint = config.hint
37+
end
38+
39+
return builder:new():set_config(config):set_hint(hint):build():pick_window()
1540
end
1641

1742
function M.setup() end

0 commit comments

Comments
 (0)