|
| 1 | +# Linenoise Next Generation |
| 2 | + |
| 3 | +A small, portable GNU readline replacement for Linux, Windows and |
| 4 | +MacOS which is capable of handling UTF-8 characters. Unlike GNU |
| 5 | +readline, which is GPL, this library uses a BSD license and can be |
| 6 | +used in any kind of program. |
| 7 | + |
| 8 | +## Origin |
| 9 | + |
| 10 | +This linenoise implementation is based on the work by |
| 11 | +[Salvatore Sanfilippo](https://github.com/antirez/linenoise) and |
| 12 | +10gen Inc. The goal is to create a zero-config, BSD |
| 13 | +licensed, readline replacement usable in Apache2 or BSD licensed |
| 14 | +programs. |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +* single-line and multi-line editing mode with the usual key bindings implemented |
| 19 | +* history handling |
| 20 | +* completion |
| 21 | +* BSD license source code |
| 22 | +* Only uses a subset of VT100 escapes (ANSI.SYS compatible) |
| 23 | +* UTF8 aware |
| 24 | +* support for Linux, MacOS and Windows |
| 25 | + |
| 26 | +It deviates from Salvatore's original goal to have a minimal readline |
| 27 | +replacement for the sake of supporting UTF8 and Windows. It deviates |
| 28 | +from 10gen Inc.'s goal to create a C++ interface to linenoise. This |
| 29 | +library uses C++ internally, but to the user it provides a pure C |
| 30 | +interface that is compatible with the original linenoise API. |
| 31 | +C interface. |
| 32 | + |
| 33 | +## Requirements |
| 34 | + |
| 35 | +To build this library, you will need a C++11-enabled compiler and |
| 36 | +some recent version of CMake. |
| 37 | + |
| 38 | +## Build instructions |
| 39 | + |
| 40 | +To build this library on Linux, first create a build directory |
| 41 | + |
| 42 | +```bash |
| 43 | +mkdir -p build |
| 44 | +``` |
| 45 | + |
| 46 | +and then build the library: |
| 47 | + |
| 48 | +```bash |
| 49 | +(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make) |
| 50 | +``` |
| 51 | + |
| 52 | +To build and install the library at the default target location, use |
| 53 | + |
| 54 | +```bash |
| 55 | +(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make && sudo make install) |
| 56 | +``` |
| 57 | + |
| 58 | +The default installation location can be adjusted by setting the `DESTDIR` |
| 59 | +variable when invoking `make install`: |
| 60 | + |
| 61 | +```bash |
| 62 | +(cd build && make DESTDIR=/tmp install) |
| 63 | +``` |
| 64 | + |
| 65 | +To build the library on Windows, use these commands in an MS-DOS command |
| 66 | +prompt: |
| 67 | + |
| 68 | +``` |
| 69 | +md build |
| 70 | +cd build |
| 71 | +``` |
| 72 | + |
| 73 | +After that, invoke the appropriate command to create the files for your |
| 74 | +target environment: |
| 75 | + |
| 76 | +* 32 bit: `cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ..` |
| 77 | +* 64 bit: `cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_BUILD_TYPE=Release ..` |
| 78 | + |
| 79 | +After that, open the generated file `linenoise.sln` from the `build` |
| 80 | +subdirectory with Visual Studio. |
| 81 | + |
| 82 | + |
| 83 | +*note: the following sections of the README.md are from the original |
| 84 | +linenoise repository and are partly outdated* |
| 85 | + |
| 86 | +## Can a line editing library be 20k lines of code? |
| 87 | + |
| 88 | +Line editing with some support for history is a really important |
| 89 | +feature for command line utilities. Instead of retyping almost the |
| 90 | +same stuff again and again it's just much better to hit the up arrow |
| 91 | +and edit on syntax errors, or in order to try a slightly different |
| 92 | +command. But apparently code dealing with terminals is some sort of |
| 93 | +Black Magic: readline is 30k lines of code, libedit 20k. Is it |
| 94 | +reasonable to link small utilities to huge libraries just to get a |
| 95 | +minimal support for line editing? |
| 96 | + |
| 97 | +So what usually happens is either: |
| 98 | + |
| 99 | + * Large programs with configure scripts disabling line editing if |
| 100 | + readline is not present in the system, or not supporting it at all |
| 101 | + since readline is GPL licensed and libedit (the BSD clone) is not |
| 102 | + as known and available as readline is (Real world example of this |
| 103 | + problem: Tclsh). |
| 104 | + |
| 105 | + * Smaller programs not using a configure script not supporting line |
| 106 | + editing at all (A problem we had with Redis-cli for instance). |
| 107 | + |
| 108 | +The result is a pollution of binaries without line editing support. |
| 109 | + |
| 110 | +So Salvatore spent more or less two hours doing a reality check |
| 111 | +resulting in this little library: is it *really* needed for a line |
| 112 | +editing library to be 20k lines of code? Apparently not, it is possibe |
| 113 | +to get a very small, zero configuration, trivial to embed library, |
| 114 | +that solves the problem. Smaller programs will just include this, |
| 115 | +supporing line editing out of the box. Larger programs may use this |
| 116 | +little library or just checking with configure if readline/libedit is |
| 117 | +available and resorting to linenoise if not. |
| 118 | + |
| 119 | +## Terminals, in 2010. |
| 120 | + |
| 121 | +Apparently almost every terminal you can happen to use today has some |
| 122 | +kind of support for basic VT100 escape sequences. So Salvatore tried |
| 123 | +to write a lib using just very basic VT100 features. The resulting |
| 124 | +library appears to work everywhere Salvatore tried to use it, and now |
| 125 | +can work even on ANSI.SYS compatible terminals, since no VT220 |
| 126 | +specific sequences are used anymore. |
| 127 | + |
| 128 | +The original library has currently about 1100 lines of code. In order |
| 129 | +to use it in your project just look at the *example.c* file in the |
| 130 | +source distribution, it is trivial. Linenoise is BSD code, so you can |
| 131 | +use both in free software and commercial software. |
| 132 | + |
| 133 | +## Tested with... |
| 134 | + |
| 135 | + * Linux text only console ($TERM = linux) |
| 136 | + * Linux KDE terminal application ($TERM = xterm) |
| 137 | + * Linux xterm ($TERM = xterm) |
| 138 | + * Linux Buildroot ($TERM = vt100) |
| 139 | + * Mac OS X iTerm ($TERM = xterm) |
| 140 | + * Mac OS X default Terminal.app ($TERM = xterm) |
| 141 | + * OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen) |
| 142 | + * IBM AIX 6.1 |
| 143 | + * FreeBSD xterm ($TERM = xterm) |
| 144 | + * ANSI.SYS |
| 145 | + * Emacs comint mode ($TERM = dumb) |
| 146 | + * Windows |
| 147 | + |
| 148 | +Please test it everywhere you can and report back! |
| 149 | + |
| 150 | +## Let's push this forward! |
| 151 | + |
| 152 | +Patches should be provided in the respect of linenoise sensibility for |
| 153 | +small and easy to understand code that and the license |
| 154 | +restrictions. Extensions must be submitted under a BSD license-style. |
| 155 | +A contributor license is required for contributions. |
| 156 | + |
0 commit comments