From 3fac6a2601016dae3a976ebdbcc5c021a54ab56b Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 1 Jan 2023 11:10:14 +0000 Subject: [PATCH] ESC cancels command --- command.fnl | 17 +++++++++++++---- frame.fnl | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/command.fnl b/command.fnl index 8c08c16..e60b75b 100644 --- a/command.fnl +++ b/command.fnl @@ -139,14 +139,22 @@ ))) -(fn activate [{: state : entry : prompt}] +(fn activate [{: state : entry : prompt &as self}] (tset state :active true) - (set entry.sensitive true) - (set entry.text "") - (set prompt.label (or state.this-param "Command" "")) + (update-widget-state + self + {:active true + :prompt (or state.this-param "Command" "") + }) (entry:grab_focus) state) +(fn deactivate [{: state : entry : prompt &as self}] + (doto state + (lume.clear) + (tset :active false)) + (update-widget-state self {:active false})) + (fn invoke-interactively [self name params] (let [c (find-command name) supplied-params (collect [k v (pairs params)] @@ -175,6 +183,7 @@ self { :state default-state : activate + : deactivate :active? (fn [self] self.state.active) : on-input : on-activate diff --git a/frame.fnl b/frame.fnl index 41badff..a7f2e6c 100644 --- a/frame.fnl +++ b/frame.fnl @@ -45,6 +45,10 @@ (match (recogniser:accept-event event) [name params] (commander:invoke-interactively name params) (nil prompt) (print "prompted" prompt))) + (when (and (commander:active?) + (= (Gdk.keyval_name event.keyval) "Escape")) + (commander:deactivate)) + (when (and event.state.MOD1_MASK (= event.keyval (string.byte "x"))) (commander:activate))))