complete command names

we really need to make TAB and Return work for keyboard-selecting
a proffered completion
This commit is contained in:
Daniel Barlow 2023-01-03 23:36:58 +00:00
parent c2c89b6dfd
commit 4d3a2bf237
1 changed files with 20 additions and 15 deletions

View File

@ -129,22 +129,27 @@
(if result.active "commander" "echo-area"))))
(fn on-input [self str]
(match self.state
{:command c :this-param param-name}
(let [parent self.completions-widget
{ : completer} (. c.params param-name)
completions (completer str)]
(parent:foreach #(parent:remove $1))
(each [text _w (pairs completions)]
(parent:add
(Gtk.Button {
:label text
:on_clicked
#(update-widget-state self (self:on-input-finished text))
})))
(parent:show_all)
)))
(let [parent self.completions-widget
set-completions
(fn [completions]
(parent:foreach #(parent:remove $1))
(each [text _w (pairs completions)]
(parent:add
(Gtk.Button {
:label text
:on_clicked
#(update-widget-state self (self:on-input-finished text))
})))
(parent:show_all))]
(match self.state
{:command c :this-param param-name}
(let [{ : completer} (. c.params param-name)]
(set-completions (completer str)))
{:command nil}
(set-completions
(collect [k _ (pairs commands)]
(if (= (k:find str 1 true) 1) (values k k)))))))
(fn activate [{: state : entry : prompt &as self}]
(tset state :active true)