You are looking at historical revision 18455 of this page. It may differ significantly from its current revision.
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.
Salvatore Sanfilippo <email@example.com>, ported to chicken by Christian Kellermann
The library is very small and exposes three procedures:
procedure: (linenoise prompt)
Prompts the user for a line of input. Returns the entered line as a string or #f if the user aborted.
procedure: (history-add line)
Adds the string line to the internal history.
procedure: (set-history-length! number)
Sets the number of maximum entries in the history. Linenoise is initialised with 100 lines of history.
- 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
Currently missing features
- No searching of history
- No deletion of whole words (ctrl-w)
- No tab completion
This example shows a minimal prompt loop echoing all user input:
(set-history-length! 300) (let loop ((l (linenoise "> "))) (if (equal? l "bye") "Bye!" (begin (display l) (newline) (history-add l) (loop (linenoise "> ")))))
- 0.1 Initial release
Copyright (c) 2010, Salvatore Sanfilippo <antirez 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. * Neither the name of Redis nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
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 OWNER 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.