- nil)
-
- (defun add-history (string)
- "Add STRING to history."
- (with-cstring (c-string string)
- (libreadline::add-history c-string))
- string)
-
- (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-from-cstring (libreadline::readline c-prompt)))))
- (when (and history (not (string= "" str)))
- (add-history str))))))
+ nil))
+
+;;; Everything that affects the custom-completion collection goes
+;;; above.
+
+
+(defun add-history (string)
+ "Add STRING to history."
+ (with-cstring (c-string string)
+ (c-add-history c-string))
+ string)
+
+(defun readline (&key (prompt "") (history t))
+ "Read a line from current TTY with line-editing."
+ (with-cstring (c-prompt prompt)
+ (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))
+ "Read an expression from current TTY with line-editing."
+ (let (expr)
+ (do* ((str (readline :prompt primary-prompt :history history)
+ (readline :prompt secondary-prompt :history history))
+ (input str (concatenate 'string input " " str)))
+ ((ignore-end-of-file
+ (setq expr (with-input-from-string (in input)
+ (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)))