(defun readline (&key (prompt "") (history t))
"Read a line from current TTY with line-editing."
(with-cstring (c-prompt prompt)
- (let ((str (string-trim *whitespace*
- (convert-and-free-foreign-string (c-readline c-prompt)))))
- (when (and history (not (string= "" str)))
- (add-history str))
+ (let* ((str (convert-and-free-foreign-string (c-readline c-prompt)))
+ (str2 (string-trim *whitespace* str)))
+ (when (and history (not (string= "" str2)))
+ (add-history str2))
str)))
-(defun readexpr (&key (primary-prompt "=> ") (secondary-prompt "| ") (history t))
+(defun readexpr (&key
+ (primary-prompt "=> ")
+ (secondary-prompt "| ")
+ (history t))
"Read an expression from current TTY with line-editing."
(let (expr)
(do* ((str (readline :prompt primary-prompt :history history)
(read in nil nil))))
expr))))
+;;
+;; Termios
+;;
-
+(def-function "no_echo"
+ ()
+ :module "cl-termios"
+ :returning :void)
+
+(def-function "restore_term"
+ ()
+ :module "cl-termios"
+ :returning :void)
+
+(defmacro without-echo (&body forms)
+ `(unwind-protect
+ (progn
+ (no-echo)
+ ,@forms)
+ (restore-term)))