From 491f3225b02b0a1b590c486119e39bcb9c42110c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 21 Dec 2022 15:24:53 +0000 Subject: [PATCH] deactivate commander at startup use M-x to activate it --- command.fnl | 13 +++++++++++-- frame.fnl | 18 +++++++++++++++--- test/command.fnl | 6 ++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/command.fnl b/command.fnl index 010df77..3fda039 100644 --- 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 index 90b6baf..e6cce8f 100644 --- 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 index 7a811e9..1d18d31 100644 --- 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