deactivate commander at startup

use M-x to activate it
main
Daniel Barlow 2022-12-21 15:24:53 +00:00
parent ce009f2c7b
commit 491f3225b0
3 changed files with 30 additions and 7 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -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