r4988: Auto commit for Debian build
[cl-readline.git] / readline.lisp
index 95c460f235689d2629427a40d1f57de72a0a39b2..ea2dedef0de5c5794710d9691403208eba6608ce 100644 (file)
 (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)))