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
local View = require("artio.view")
2
3
-
---@alias artio.Picker.item { id: integer, v: string, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] }
4
---@alias artio.Picker.match [integer, integer[], integer] [item, pos[], score]
5
---@alias artio.Picker.sorter fun(lst: artio.Picker.item[], input: string): artio.Picker.match[]
6
---@alias artio.Picker.hl [[integer, integer], string]
7
8
-
---@class artio.Picker.proto<T>
9
-
---@field items? artio.Picker.item[]
10
-
---@field fn? artio.Picker.sorter
11
-
---@field on_close? fun(text: string, idx: integer)
12
-
---@field format_item? fun(item: string): string
13
-
---@field preview_item? fun(item: string): integer, fun(win: integer)
14
---@field get_icon? fun(item: artio.Picker.item): string, string
15
---@field hl_item? fun(item: artio.Picker.item): artio.Picker.hl[]
16
---@field opts? artio.config.opts
···
19
---@field defaulttext? string
20
---@field prompttext? string
21
22
-
---@class artio.Picker : artio.Picker.proto
23
---@field idx integer 1-indexed
24
---@field matches artio.Picker.match[]
25
local Picker = {}
26
Picker.__index = Picker
27
28
-
---@param props artio.Picker.proto
29
function Picker:new(props)
30
-
vim.validate("fn", props.fn, "function")
31
-
vim.validate("on_close", props.on_close, "function")
0
32
33
local t = vim.tbl_deep_extend("force", {
34
closed = false,
···
62
end
63
64
function Picker:open()
65
-
if not self.fn or not self.on_close then
66
-
vim.notify("Picker must have `fn` and `on_close`", vim.log.levels.ERROR)
67
-
return
68
-
end
69
-
70
local accepted
71
local cancelled
72
73
-
self.view = View:new()
74
-
self.view.picker = self
75
76
coroutine.wrap(function()
77
self.view:open()
···
1
local View = require("artio.view")
2
3
+
---@alias artio.Picker.item { id: integer, v: any, text: string, icon?: string, icon_hl?: string, hls?: artio.Picker.hl[] }
4
---@alias artio.Picker.match [integer, integer[], integer] [item, pos[], score]
5
---@alias artio.Picker.sorter fun(lst: artio.Picker.item[], input: string): artio.Picker.match[]
6
---@alias artio.Picker.hl [[integer, integer], string]
7
8
+
---@class artio.Picker.config
9
+
---@field items artio.Picker.item[]
10
+
---@field fn artio.Picker.sorter
11
+
---@field on_close fun(text: string, idx: integer)
12
+
---@field format_item? fun(item: any): string
13
+
---@field preview_item? fun(item: any): integer, fun(win: integer)
14
---@field get_icon? fun(item: artio.Picker.item): string, string
15
---@field hl_item? fun(item: artio.Picker.item): artio.Picker.hl[]
16
---@field opts? artio.config.opts
···
19
---@field defaulttext? string
20
---@field prompttext? string
21
22
+
---@class artio.Picker : artio.Picker.config
23
---@field idx integer 1-indexed
24
---@field matches artio.Picker.match[]
25
local Picker = {}
26
Picker.__index = Picker
27
28
+
---@param props artio.Picker.config
29
function Picker:new(props)
30
+
vim.validate("Picker.items", props.items, "table")
31
+
vim.validate("Picker:fn", props.fn, "function")
32
+
vim.validate("Picker:on_close", props.on_close, "function")
33
34
local t = vim.tbl_deep_extend("force", {
35
closed = false,
···
63
end
64
65
function Picker:open()
0
0
0
0
0
66
local accepted
67
local cancelled
68
69
+
self.view = View:new(self)
0
70
71
coroutine.wrap(function()
72
self.view:open()
+3
-1
lua/artio/view.lua
···
57
local View = {}
58
View.__index = View
59
60
-
function View:new()
0
61
return setmetatable({
0
62
closed = false,
63
win = {
64
height = 0,
···
57
local View = {}
58
View.__index = View
59
60
+
---@param picker artio.Picker
61
+
function View:new(picker)
62
return setmetatable({
63
+
picker = picker,
64
closed = false,
65
win = {
66
height = 0,