tangled
alpha
login
or
join now
robinwobin.dev
/
artio.nvim
3
fork
atom
minimal extui fuzzy finder for neovim
3
fork
atom
overview
issues
pulls
pipelines
fix: types and class initialisation
robinwobin.dev
3 months ago
73442480
8481c0a0
+16
-19
2 changed files
expand all
collapse all
unified
split
lua
artio
picker.lua
view.lua
+13
-18
lua/artio/picker.lua
···
1
1
local View = require("artio.view")
2
2
3
3
-
---@alias artio.Picker.item { id: integer, v: string, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] }
3
3
+
---@alias artio.Picker.item { id: integer, v: any, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] }
4
4
---@alias artio.Picker.match [integer, integer[], integer] [item, pos[], score]
5
5
---@alias artio.Picker.sorter fun(lst: artio.Picker.item[], input: string): artio.Picker.match[]
6
6
---@alias artio.Picker.hl [[integer, integer], string]
7
7
8
8
-
---@class artio.Picker.proto<T>
9
9
-
---@field items? artio.Picker.item[]
10
10
-
---@field fn? artio.Picker.sorter
11
11
-
---@field on_close? fun(text: string, idx: integer)
12
12
-
---@field format_item? fun(item: string): string
13
13
-
---@field preview_item? fun(item: string): integer, fun(win: integer)
8
8
+
---@class artio.Picker.config
9
9
+
---@field items artio.Picker.item[]
10
10
+
---@field fn artio.Picker.sorter
11
11
+
---@field on_close fun(text: string, idx: integer)
12
12
+
---@field format_item? fun(item: any): string
13
13
+
---@field preview_item? fun(item: any): integer, fun(win: integer)
14
14
---@field get_icon? fun(item: artio.Picker.item): string, string
15
15
---@field hl_item? fun(item: artio.Picker.item): artio.Picker.hl[]
16
16
---@field opts? artio.config.opts
···
19
19
---@field defaulttext? string
20
20
---@field prompttext? string
21
21
22
22
-
---@class artio.Picker : artio.Picker.proto
22
22
+
---@class artio.Picker : artio.Picker.config
23
23
---@field idx integer 1-indexed
24
24
---@field matches artio.Picker.match[]
25
25
local Picker = {}
26
26
Picker.__index = Picker
27
27
28
28
-
---@param props artio.Picker.proto
28
28
+
---@param props artio.Picker.config
29
29
function Picker:new(props)
30
30
-
vim.validate("fn", props.fn, "function")
31
31
-
vim.validate("on_close", props.on_close, "function")
30
30
+
vim.validate("Picker.items", props.items, "table")
31
31
+
vim.validate("Picker:fn", props.fn, "function")
32
32
+
vim.validate("Picker:on_close", props.on_close, "function")
32
33
33
34
local t = vim.tbl_deep_extend("force", {
34
35
closed = false,
···
62
63
end
63
64
64
65
function Picker:open()
65
65
-
if not self.fn or not self.on_close then
66
66
-
vim.notify("Picker must have `fn` and `on_close`", vim.log.levels.ERROR)
67
67
-
return
68
68
-
end
69
69
-
70
66
local accepted
71
67
local cancelled
72
68
73
73
-
self.view = View:new()
74
74
-
self.view.picker = self
69
69
+
self.view = View:new(self)
75
70
76
71
coroutine.wrap(function()
77
72
self.view:open()
+3
-1
lua/artio/view.lua
···
57
57
local View = {}
58
58
View.__index = View
59
59
60
60
-
function View:new()
60
60
+
---@param picker artio.Picker
61
61
+
function View:new(picker)
61
62
return setmetatable({
63
63
+
picker = picker,
62
64
closed = false,
63
65
win = {
64
66
height = 0,