From: Kevin M. Rosenberg Date: Fri, 16 May 2003 18:58:09 +0000 (+0000) Subject: r4988: Auto commit for Debian build X-Git-Tag: debian-0.2.0-4~13 X-Git-Url: http://git.kpe.io/?p=cl-readline.git;a=commitdiff_plain;h=8e1c2386d4bd733c6b82717dec20248ed1d82019 r4988: Auto commit for Debian build --- diff --git a/Makefile b/Makefile index 9a68259..fb4c684 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ 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 diff --git a/README b/README index 2f536ac..0c252bc 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -CL-READLINE 0.2.0 +CL-READLINE 0.3.0 CL-READLINE is a simple UFFI-based wrapper for the GNU Readline library. @@ -7,24 +7,33 @@ CL-READLINE 0.2.0 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 @@ -38,27 +47,41 @@ Functions: 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. diff --git a/changelog b/changelog new file mode 100644 index 0000000..08c867e --- /dev/null +++ b/changelog @@ -0,0 +1,36 @@ +2003-05-16 Nikodemus Siivola + + * 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 + + * 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 + + * 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 + + * README: Added function documentation. + + * readline.lisp (readline): Fixed memory leak in FFI code. + + * libreadline.lisp (readline): Changed return type. + diff --git a/cl-termios.c b/cl-termios.c new file mode 100644 index 0000000..cfc9a8b --- /dev/null +++ b/cl-termios.c @@ -0,0 +1,78 @@ +/* + * 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 +#include +#include + +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; +} diff --git a/debian/changelog b/debian/changelog index 32dbfab..8c1207e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cl-readline (0.3.0-1) unstable; urgency=low + + * New upstream + + -- Kevin M. Rosenberg Fri, 16 May 2003 12:55:31 -0600 + cl-readline (0.2.0-1) unstable; urgency=low * New upstream diff --git a/debian/docs b/debian/docs index 724e084..78dbe26 100644 --- a/debian/docs +++ b/debian/docs @@ -1,2 +1,3 @@ README TODO +ChangeLog diff --git a/packages.lisp b/packages.lisp index dd801cf..51c0b1a 100644 --- a/packages.lisp +++ b/packages.lisp @@ -28,12 +28,18 @@ 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") + diff --git a/readline.asd b/readline.asd index 835529c..ea2c86b 100644 --- a/readline.asd +++ b/readline.asd @@ -25,3 +25,4 @@ :components ((:file "packages") (:file "readline" :depends-on ("packages")))) + diff --git a/readline.lisp b/readline.lisp index 95c460f..ea2dede 100644 --- a/readline.lisp +++ b/readline.lisp @@ -101,13 +101,16 @@ (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) @@ -118,5 +121,23 @@ (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)))