xref: /illumos-gate/usr/src/boot/common/linenoise/README.markdown (revision 22028508fd28d36ff74dc02c5774a8ba1f0db045)
1*22028508SToomas Soome# Linenoise
2*22028508SToomas Soome
3*22028508SToomas SoomeA minimal, zero-config, BSD licensed, readline replacement used in Redis,
4*22028508SToomas SoomeMongoDB, and Android.
5*22028508SToomas Soome
6*22028508SToomas Soome* Single and multi line editing mode with the usual key bindings implemented.
7*22028508SToomas Soome* History handling.
8*22028508SToomas Soome* Completion.
9*22028508SToomas Soome* About 1,100 lines of BSD license source code.
10*22028508SToomas Soome* Only uses a subset of VT100 escapes (ANSI.SYS compatible).
11*22028508SToomas Soome
12*22028508SToomas Soome## Can a line editing library be 20k lines of code?
13*22028508SToomas Soome
14*22028508SToomas SoomeLine 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?
15*22028508SToomas Soome
16*22028508SToomas SoomeSo what usually happens is either:
17*22028508SToomas Soome
18*22028508SToomas Soome * Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).
19*22028508SToomas Soome * Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).
20*22028508SToomas Soome
21*22028508SToomas SoomeThe result is a pollution of binaries without line editing support.
22*22028508SToomas Soome
23*22028508SToomas SoomeSo I spent more or less two hours doing a reality check resulting in this little library: is it *really* needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporing line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to linenoise if not.
24*22028508SToomas Soome
25*22028508SToomas Soome## Terminals, in 2010.
26*22028508SToomas Soome
27*22028508SToomas SoomeApparently almost every terminal you can happen to use today has some kind of support for basic VT100 escape sequences. So I tried to write a lib using just very basic VT100 features. The resulting library appears to work everywhere I tried to use it, and now can work even on ANSI.SYS compatible terminals, since no
28*22028508SToomas SoomeVT220 specific sequences are used anymore.
29*22028508SToomas Soome
30*22028508SToomas SoomeThe library is currently about 1100 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
31*22028508SToomas Soome
32*22028508SToomas Soome## Tested with...
33*22028508SToomas Soome
34*22028508SToomas Soome * Linux text only console ($TERM = linux)
35*22028508SToomas Soome * Linux KDE terminal application ($TERM = xterm)
36*22028508SToomas Soome * Linux xterm ($TERM = xterm)
37*22028508SToomas Soome * Linux Buildroot ($TERM = vt100)
38*22028508SToomas Soome * Mac OS X iTerm ($TERM = xterm)
39*22028508SToomas Soome * Mac OS X default Terminal.app ($TERM = xterm)
40*22028508SToomas Soome * OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
41*22028508SToomas Soome * IBM AIX 6.1
42*22028508SToomas Soome * FreeBSD xterm ($TERM = xterm)
43*22028508SToomas Soome * ANSI.SYS
44*22028508SToomas Soome
45*22028508SToomas SoomePlease test it everywhere you can and report back!
46*22028508SToomas Soome
47*22028508SToomas Soome## Let's push this forward!
48*22028508SToomas Soome
49*22028508SToomas SoomePatches should be provided in the respect of linenoise sensibility for small
50*22028508SToomas Soomeeasy to understand code.
51*22028508SToomas Soome
52*22028508SToomas SoomeSend feedbacks to antirez at gmail
53