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

  1. Outdated egg!
  2. Linenoise
    1. Description
    2. Author
    3. Interface
    4. Controls
    5. Currently missing features
    6. Example
    7. Using linenoise in csi
    8. Changelog
    9. License

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?

(...)

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:

[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.

[procedure] (save-history-to-file filename)

Saves the current history buffer to filename.

[procedure] (load-history-from-file filename)

Loads the history from file.

[procedure] (make-linenoise-port)

Returns an input port connected to a linenoise prompt. Useful for inserting it into CSI (see below).

Controls

Currently missing features

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.