commit 491f3225b02b0a1b590c486119e39bcb9c42110c
parent ce009f2c7babb8c8c3608474c5d0bcb2b3c51976
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 21 Dec 2022 15:24:53 +0000
deactivate commander at startup
use M-x to activate it
Diffstat:
3 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/command.fnl b/command.fnl
@@ -25,7 +25,7 @@
(. commands name))
(local default-state {
- :active true
+ :active false
:command nil
:collected-params {}
:this-param nil
@@ -90,4 +90,13 @@
:default (and param (param))
}))
-{ : define-command : on-input : reset-state }
+(fn activate []
+ (tset state :active true)
+ state)
+
+{
+ : activate
+ : define-command
+ : on-input
+ : reset-state
+ }
diff --git a/frame.fnl b/frame.fnl
@@ -17,6 +17,7 @@
:orientation Gtk.Orientation.VERTICAL
})
commander (Gtk.Entry {
+ :sensitive false
})
progress-bar (Gtk.ProgressBar {
:orientation Gtk.Orientation.HORIZONTAL
@@ -30,9 +31,20 @@
(tset commander :on_activate
(fn [event]
(let [result (Command.on-input event.text)]
- (print "result" (view result))
- (set commander.placeholder_text (or result.prompt ""))
- (set commander.text (or result.default "")))))
+ (set commander.placeholder_text
+ (or result.prompt ""))
+ (set commander.sensitive result.active)
+ (set commander.text
+ (or result.default result.error "")))))
+
+ (tset window :on_key_release_event
+ (fn [window event]
+ (when (and event.state.MOD1_MASK
+ (= event.keyval (string.byte "x")))
+ (set commander.sensitive true)
+ (set commander.text "")
+ (commander:grab_focus)
+ (Command.activate))))
(doto container
(: :pack_start commander false false vpad)
diff --git a/test/command.fnl b/test/command.fnl
@@ -14,7 +14,8 @@
(before)
(let [(ok err)
- (match-try (Command.on-input "not-a-command")
+ (match-try (Command.activate)
+ {:active true} (Command.on-input "not-a-command")
(where {:error e :active false} (e:match "can't find command")) true
(catch
x (values nil (view x))))]
@@ -22,7 +23,8 @@
(before)
(let [(ok err)
- (match-try (Command.on-input "multiply")
+ (match-try (Command.activate)
+ {:active true} (Command.on-input "multiply")
{:active true :prompt p1} (Command.on-input "2")
{:active true :prompt p2} (Command.on-input "3")
(where {:active false} (= happened 6)) true