basename:=cl-readline
+basename2:=cl-termios
all: $(basename).o
all:
gcc -fPIC -DPIC -c $(basename).c -o $(basename).o
+ gcc -fPIC -DPIC -c $(basename2).c -o $(basename2).o
gcc -shared $(basename).o -lreadline -o $(basename).so
-CL-READLINE 0.2.0
+CL-READLINE 0.3.0
CL-READLINE is a simple UFFI-based wrapper for the GNU Readline
library.
and CMUCL. Other platforms and UFFI compatible implementations should
work, but may require tweaking.
- To load:
+ To load:
(asdf:oos 'asdf:load-op 'readline)
- The interface exported by the package READLINE (nicknamed RL).
+ CL-READLINE behaviour can be modified via ~/.inputrc, see GNU
+ Readline documentation for details.
-Functions:
- READLINE &key prompt history
+API
+
+ (exported by "READLINE" package, nicknamed "RL")
- prompt -- a string (default "")
- history -- a boolean (default t)
- Prompt is the prompt displayed to user.
+ ADD-COMPLETION
+
+ Add a completion to the custom completion pool.
+
+
+ ADD-HISTORY string
+
+ Adds the given string to history.
+
+
+ CLEAR-COMPLETIONS
+
+ Empty the custom completion pool.
- History controls whether the string read is added to history, or
- not. Note that history is available in any case. Currently there
- is no way to erase history.
READEXPR &key primary-prompt secondary-prompt history
Primary-prompt controls the prompt of the first line,
secondary prompt the prompt of the rest of the lines.
- ADD-HISTORY string
- Adds the given string to history.
+ READLINE &key prompt history
- USE-FILENAME-COMPLETE
+ prompt -- a string (default "")
+ history -- a boolean (default t)
- Use the Readline's default filename-completion system.
+ Prompt is the prompt displayed to user.
- USE-PACKAGE-COMPLETE name
+ History controls whether the string read is added to history, or
+ not. Note that history is available in any case. Currently there
+ is no way to erase history. Leading and trailing whitespace is trimmed
+ from string before they are added to history, and strings that consist
+ entirely of whitespace are not saved to history.
+
+ Dispite the cleanups performed on history, strings are returned as
+ read.
- Insert symbols in package designated by NAME to the custom
- completion pool, and start using the custom completion system.
USE-CUSTOM-COMPLETE
- Use the custom completion system.
+ Use the custom completion system.
- ADD-COMPLETION
- Add a completion to the custom completion pool.
+ USE-FILENAME-COMPLETE
- CLEAR-COMPLETIONS
+ Use the Readline's default filename-completion system.
- Empty the custom completion pool.
+
+ USE-PACKAGE-COMPLETE name
+
+ Clear current custom completion pool, insert symbols in package
+ designated by NAME to the custom completion pool, and start using
+ the custom completion system.
+
+
+ WITHOUT-ECHO form*
+
+ Runs forms without echoing of input on screen.
--- /dev/null
+2003-05-16 Nikodemus Siivola <tsiivola@cc.hut.fi>
+
+ * README: Added documentation for WITHOUT-ECHO, and misc. doc
+ updates.
+
+ * readline.lisp ("no_echo"): New FFI definition
+ ("restore_term"): New FFI definition
+ (without-echo): New macro
+
+ * cl-termios.c: New file
+
+2003-05-08 Nikodemus Siivola <tsiivola@cc.hut.fi>
+
+ * README (Functions): Added documentation for READEXPR.
+
+ * readline.lisp (readexpr): New function.
+
+ * libreadline.lisp: Moved c-functions to readline.lisp, as it
+ turned out that name conflict were avoidable without separate
+ packages.
+
+2003-05-06 Nikodemus Siivola <tsiivola@cc.hut.fi>
+
+ * readline.asd (asdf:load-op): Use ASDF to load UFFI instead of
+ require.
+
+ * readline.lisp (from-foreign-string): New function.
+
+2003-05-05 Nikodemus Siivola <tsiivola@cc.hut.fi>
+
+ * README: Added function documentation.
+
+ * readline.lisp (readline): Fixed memory leak in FFI code.
+
+ * libreadline.lisp (readline): Changed return type.
+
--- /dev/null
+/*
+ * Copyright (c) 2003 Nikodemus Siivola
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <termios.h>
+#include <stdlib.h>
+
+typedef struct {
+ struct termios *attr;
+ void *next;
+}
+state_t;
+
+state_t * stack = NULL;
+
+int
+save_term (void)
+{
+ state_t * state = malloc (sizeof (state_t));
+ struct termios * attr = malloc (sizeof (struct termios));
+ if (! (state && attr))
+ return 0;
+
+ tcgetattr (STDIN_FILENO, attr);
+
+ state->attr = attr;
+ state->next = stack;
+ stack = state;
+
+ return 1;
+}
+
+void
+restore_term (void)
+{
+ state_t * tmp = stack;
+ if (!stack) return;
+
+ tcsetattr (STDIN_FILENO, TCSANOW, stack->attr);
+ stack = stack->next;
+
+ free (tmp->attr);
+ free (tmp);
+}
+
+int
+no_echo (void)
+{
+ struct termios attr;
+ if (! (isatty (STDIN_FILENO) && save_term ()))
+ return 0;
+
+ tcgetattr (STDIN_FILENO, &attr);
+ attr.c_lflag &= ~ECHO;
+ tcsetattr (STDIN_FILENO, TCSAFLUSH, &attr);
+
+ return 1;
+}
+cl-readline (0.3.0-1) unstable; urgency=low
+
+ * New upstream
+
+ -- Kevin M. Rosenberg <kmr@debian.org> Fri, 16 May 2003 12:55:31 -0600
+
cl-readline (0.2.0-1) unstable; urgency=low
* New upstream
clear-completions
readline
readexpr
- repl
use-package-complete
use-custom-complete
use-filename-complete
+ without-echo
))
-(uffi:load-foreign-library "/usr/lib/cl-readline/cl-readline.so"
+(uffi:load-foreign-library "/lib/libreadline.so.4"
+ :module "readline")
+
+(uffi:load-foreign-library "cl-readline.o"
:module "cl-readline")
+(uffi:load-foreign-library "cl-termios.o"
+ :module "cl-termios")
+
:components ((:file "packages")
(:file "readline" :depends-on ("packages"))))
+
(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)))