From 4d3a2bf23740f18a40130737e7c104c9637d2d98 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 3 Jan 2023 23:36:58 +0000 Subject: [PATCH] complete command names we really need to make TAB and Return work for keyboard-selecting a proffered completion --- command.fnl | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/command.fnl b/command.fnl index 05e66f0..77a1ca6 100644 --- a/command.fnl +++ b/command.fnl @@ -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)