Support exit using ^D - clic - Clic is an command line interactive client for gopher written in Common LISP HTML git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 8728b1f94663cfc4f8c6eb664263e8b216f8b3e5 DIR parent 57ee48248441d6a164067c9652f20721a284757a HTML Author: Solene Rapenne <solene@perso.pw> Date: Sat, 27 Jan 2018 23:36:53 +0100 Support exit using ^D Diffstat: M README.md | 3 +-- M clic.lisp | 69 +++++++++++++++++-------------- 2 files changed, 39 insertions(+), 33 deletions(-) --- DIR diff --git a/README.md b/README.md @@ -73,8 +73,7 @@ Keyboard bindings + p : previous page + h : display history + r : reload the page -+ x : quit shell mode -+ q : quit shell mode ++ x or q or ^D : quit + / pattern : redisplay the menu only with lines containing pattern (no regex) + d : display the raw response DIR diff --git a/clic.lisp b/clic.lisp @@ -386,16 +386,16 @@ (defun help-shell() "show help for the shell" - (format t "number : go to link n~%") - (format t "p or / : go to previous page~%") - (format t "h : display history~%") - (format t "b or - : display bookmarks and choose a link from it~%") - (format t "a or + : add a bookmark~%") - (format t "r or * : reload the page~%") - (format t "help : show this help~%") - (format t "d : dump the raw reponse~%") - (format t "/ text : display online lines matching text~%") - (format t "x or q or . : exit the shell, go back to REPL~%")) + (format t "number : go to link n~%") + (format t "p or / : go to previous page~%") + (format t "h : display history~%") + (format t "b or - : display bookmarks and choose a link from it~%") + (format t "a or + : add a bookmark~%") + (format t "r or * : reload the page~%") + (format t "help : show this help~%") + (format t "d : dump the raw reponse~%") + (format t "/ text : display online lines matching text~%") + (format t "^D or x or q or . : quit clic~%")) (defun parse-url(url) "parse a gopher url and return a location" @@ -481,6 +481,7 @@ ;; exit ((or + (eql nil input) (string= "." input) (string= "exit" input) (string= "x" input) @@ -573,15 +574,20 @@ (get-color 'bg-black) (get-color 'reset)) (force-output) - (let ((first-input (read-char))) - (if (char= #\NewLine first-input) - ;; we hide previous line (prompt) - (format t "'~C[A~C[K~C" #\Escape #\Escape #\return) - (progn - (unread-char first-input) - (let ((input-text (format nil "~a" (read-line nil nil)))) - (setf input input-text) - (loop-finish))))))) + (let ((first-input (read-char *standard-input* nil nil t))) + (cond + ((not first-input) + (format t "~%") ;; display a newline + (setf input "x") ;; we exit + (loop-finish)) + ((char= #\NewLine first-input) + ;; we hide previous line (prompt) + (format t "'~C[A~C[K~C" #\Escape #\Escape #\return)) + (t + (unread-char first-input) + (let ((input-text (format nil "~a" (read-line nil nil)))) + (setf input input-text) + (loop-finish))))))) ;; in case of shell command, do it (if input @@ -649,14 +655,15 @@ ;; we loop until X or Q is typed (loop for input = (format nil "~a" (read-line nil nil)) - while (not (or - (string= "exit" input) - (string= "x" input) - (string= "q" input))) - do - (when (eq 'end (user-input input)) - (loop-finish)) - (display-prompt))) + while (not (or + (string= "NIL" input) ;; ^D + (string= "exit" input) + (string= "x" input) + (string= "q" input))) + do + (when (eq 'end (user-input input)) + (loop-finish)) + (display-prompt))) (defun main() "fetch argument, display page and go to shell if type is 1" @@ -675,10 +682,10 @@ ;; if user want to drop from first page we need ;; to look it here - (when (not (eq 'end (visit destination))) - ;; we continue to the shell if we are in a terminal - (when (ttyp) - (shell)))))) + (when (not (eq 'end (visit destination))) + ;; we continue to the shell if we are in a terminal + (when (ttyp) + (shell)))))) ;; we allow ecl to use a new kind of argument ;; not sure how it works but that works