You are looking at historical revision 19689 of this page. It may differ significantly from its current revision.

Linenoise

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

Controls

Currently missing features

Example

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 "> ")))))

Changelog

License

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.