From 84d2d7a5e054b48062b959a18a39f139c0919586 Mon Sep 17 00:00:00 2001 From: cage Date: Fri, 1 Mar 2024 14:57:36 +0100 Subject: [PATCH] - added keybinding to cancel inputing of the string command. --- doc/tinmop.man | 2 ++ doc/tinmop.org | 1 + src/command-window.lisp | 13 +++++++++++-- src/program-events.lisp | 5 +++-- src/ui-goodies.lisp | 7 +++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/doc/tinmop.man b/doc/tinmop.man index 634dfe1..5dc11cd 100644 --- a/doc/tinmop.man +++ b/doc/tinmop.man @@ -172,6 +172,8 @@ the \fBnew line\fP (often called \fBenter\fP key) send the input to the program; .IP \(em 4 \fBC-k\fP (that is: "press 'control' and while pressed press 'k') \fIkills\fP (deletes) the text from the cursor position to the end of the input previously typed; .IP \(em 4 +\fBC-g\fP will cancel the prompt and quit the command; +.IP \(em 4 press \fBM-left\fP and \fBM-right\fP (\fBleft alt\fP and \fBleft\fP or \fBright\fP arrow together) to browse pages of the suggestion window; the suggestion window is a window that holds a previously inputted data that are compatible with the string the user is typing into the command window; .IP \(em 4 if suggestions are gemini URI press \fBTAB\fP to input the current selected suggestion; diff --git a/doc/tinmop.org b/doc/tinmop.org index 4331fc2..152cfe8 100644 --- a/doc/tinmop.org +++ b/doc/tinmop.org @@ -116,6 +116,7 @@ - *canc* and *backspace* delete the next and previous character respectively; - the *new line* (often called *enter* key) send the input to the program; - *C-k* (that is: "press 'control' and while pressed press 'k') /kills/ (deletes) the text from the cursor position to the end of the input previously typed; + - *C-g* will cancel the prompt and quit the command; - press *M-left* and *M-right* (*left alt* and *left* or *right* arrow together) to browse pages of the suggestion window; the suggestion window is a window that holds a previously inputted data that are compatible with the string the user is typing into the command window; - if suggestions are gemini URI press *TAB* to input the current selected suggestion; - if suggestion window is *not* rendered, pressing *up* and *down* arrow keys will cycle through input history, if there is not a suggestion window rendered pressing *up* and *down* will scroll on suggestions. diff --git a/src/command-window.lisp b/src/command-window.lisp index da4edc1..671fcbd 100644 --- a/src/command-window.lisp +++ b/src/command-window.lisp @@ -464,7 +464,7 @@ be either `:keybinding' or `:string'. the former for key command the latter for (move-point-to-end win command-line))))) win) -(defun fire-user-input-event (win) +(defun fire-user-input-event (win &key (canceled nil)) "Generates an event to notify that the user inserted an input on the command line." (with-accessors ((event-to-answer event-to-answer) @@ -480,11 +480,15 @@ command line." :condition-variable (program-events:condition-variable event-to-answer)))) (setf (box:dunbox (program-events:payload input-done-event)) - command-line) + (if canceled + :canceled + command-line)) (program-events:push-event input-done-event)))) (define-constant +event-cut-line+ "^K" :test #'string=) +(define-constant +event-cancel-command-line+ "^G" :test #'string=) + (defun manage-string-event (command-window event) "Manage UI events when `command-window` is in string mode" (with-accessors ((command-line command-line) @@ -508,6 +512,11 @@ command line." (cond ((string= decoded-event +event-cut-line+) (setf command-line (safe-subseq command-line 0 (no-prompt-point-pos command-window)))) + ((string= decoded-event +event-cancel-command-line+) + (setf command-line nil) + (move-point-to-start command-window) + (set-keybinding-mode command-window) + (fire-user-input-event command-window :canceled t)) ((eq :alt-left original-key-event) (move-suggestion-page-left command-window)) ((eq :alt-right original-key-event) diff --git a/src/program-events.lisp b/src/program-events.lisp index aa99e29..149d617 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -297,9 +297,10 @@ :accessor complete-fn)) (:documentation "This events, when processed, will prepare the command-window `specials:*command-window*' to ask for user - input. The most importatn thing is that the process-event will set + input. The most important thing is that the process-event will bind the slot `command-window:event-to-answer' with this events and will - set the payload of this events with the user provided string.")) + bind the slot `payload' of this events with the user provided + string.")) (defmethod initialize-instance :after ((object ask-user-input-string-event) &key (forced-priority nil) &allow-other-keys) diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 8cd31b7..ac7f971 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -248,8 +248,11 @@ do (condition-wait condition-variable lock)) (setf (command-window:echo-character *command-window*) nil) - (funcall on-input-complete-fn (box:dunbox (payload event)))))))) - (make-thread #'thread-fn))) + (let ((input-string (box:dunbox (payload event)))) + (if (stringp input-string) + (funcall on-input-complete-fn input-string) + (info-message (_ "Command cancelled"))))))))) + (make-thread #'thread-fn))) (defun thread-go-up () (thread-window:go-message-up *thread-window*))