Outdated egg!
This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
Linenoise
TOC »
Description
A minimal, zero-config, BSD licensed, readline replacement.
From the author's readme:
Line editing with some support for history is a really important feature for command line utilities. Instead of retyping almost the same stuff again and again it's just much better to hit the up arrow and edit on syntax errors, or in order to try a slightly different command. But apparently code dealing with terminals is some sort of Black Magic: readline is 30k lines of code, libedit 20k. Is it reasonable to link small utilities to huge libraries just to get a minimal support for line editing?
(...)
- Linux text only console ($TERM = linux)
- Linux KDE terminal application ($TERM = xterm)
- Linux xterm ($TERM = xterm)
- Mac OS X iTerm ($TERM = xterm)
- Mac OS X default Terminal.app ($TERM = xterm)
- OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
- IBM AIX 6.1
- FreeBSD xterm ($TERM = xterm)
This information has been collected on 2010-06-13.
Author
Salvatore Sanfilippo <antirez@gmail.com>, ported to chicken by Christian Kellermann
Interface
The library is very small and exposes six procedures:
- linenoise promptprocedure
Prompts the user for a line of input. Returns the entered line as a string or #f if the user aborted.
- history-add lineprocedure
Adds the string line to the internal history.
- set-history-length! numberprocedure
Sets the number of maximum entries in the history. Linenoise is initialised with 100 lines of history.
- save-history-to-file filenameprocedure
Saves the current history buffer to filename.
- load-history-from-file filenameprocedure
Loads the history from file.
- make-linenoise-portprocedure
Returns an input port connected to a linenoise prompt. Useful for inserting it into CSI (see below).
Controls
- arrow keys move the cursor, as well as ctrl-b, ctrl-f (back and forward), ctrl-p and ctrl-n (up / down)
- ctrl-d and enter will finish the input and a string containing the current line will be returned.
- ctrl-c aborts input and the linenoise procedure will return #f
- Deletion of one character is done by pressing backspace or ctrl-h
- ctrl-u deletes the whole line
- ctrl-k deletes from point (the cursor) to the end of the line
- ctrl-a moves to the beginning of the line
- ctrl-e moves to the end of the line
- ctrl-t permutes the char after the cursor with the one under the cursor
Currently missing features
- No searching of history
- No deletion of whole words (ctrl-w)
- No tab completion
Example
This example shows a minimal prompt loop echoing all user input:
(use linenoise) (set-history-length! 300) (load-history-from-file ".linenoise-history") (let loop ((l (linenoise "> "))) (cond ((equal? l "bye") (save-history-to-file ".linenoise-history") "Bye!") (else (display l) (newline) (history-add l) (loop (linenoise "> ")))))
Using linenoise in csi
Since version 0.4 linenoise can be used as editing help in csi, simply add the following to your .csirc
(use linenoise) (current-input-port (make-linenoise-port))
Changelog
- 0.7 Merge with upstream sources (2013-07-17)
- 0.6 Merge with upstream sources (2011-03-30)
- 0.5 Merge with upstream sources (2010-09-24)
- 0.4 Provide a input port for csi
- 0.3 Get rid of easyffi dependency
- 0.2 Update from upstream sources (2010-08-29)
- 0.1 Initial release
License
Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com> Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.