- Notifications
You must be signed in to change notification settings - Fork53
A small self-contained alternative to readline and libedit that supports UTF-8 and Windows and is BSD licensed.
License
arangodb/linenoise-ng
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A small, portable GNU readline replacement for Linux, Windows andMacOS which is capable of handling UTF-8 characters. Unlike GNUreadline, which is GPL, this library uses a BSD license and can beused in any kind of program.
This linenoise implementation is based on the work bySalvatore Sanfilippo and10gen Inc. The goal is to create a zero-config, BSDlicensed, readline replacement usable in Apache2 or BSD licensedprograms.
- single-line and multi-line editing mode with the usual key bindings implemented
- history handling
- completion
- BSD license source code
- Only uses a subset of VT100 escapes (ANSI.SYS compatible)
- UTF8 aware
- support for Linux, MacOS and Windows
It deviates from Salvatore's original goal to have a minimal readlinereplacement for the sake of supporting UTF8 and Windows. It deviatesfrom 10gen Inc.'s goal to create a C++ interface to linenoise. Thislibrary uses C++ internally, but to the user it provides a pure Cinterface that is compatible with the original linenoise API.C interface.
To build this library, you will need a C++11-enabled compiler andsome recent version of CMake.
To build this library on Linux, first create a build directory
mkdir -p build
and then build the library:
(cd build&& cmake -DCMAKE_BUILD_TYPE=Release ..&& make)
To build and install the library at the default target location, use
(cd build&& cmake -DCMAKE_BUILD_TYPE=Release ..&& make&& sudo make install)
The default installation location can be adjusted by setting theDESTDIR
variable when invokingmake install
:
(cd build&& make DESTDIR=/tmp install)
To build the library on Windows, use these commands in an MS-DOS commandprompt:
md buildcd build
After that, invoke the appropriate command to create the files for yourtarget environment:
- 32 bit:
cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ..
- 64 bit:
cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_BUILD_TYPE=Release ..
After that, open the generated filelinenoise.sln
from thebuild
subdirectory with Visual Studio.
note: the following sections of the README.md are from the originallinenoise repository and are partly outdated
Line editing with some support for history is a really importantfeature for command line utilities. Instead of retyping almost thesame stuff again and again it's just much better to hit the up arrowand edit on syntax errors, or in order to try a slightly differentcommand. But apparently code dealing with terminals is some sort ofBlack Magic: readline is 30k lines of code, libedit 20k. Is itreasonable to link small utilities to huge libraries just to get aminimal support for line editing?
So what usually happens is either:
Large programs with configure scripts disabling line editing ifreadline is not present in the system, or not supporting it at allsince readline is GPL licensed and libedit (the BSD clone) is notas known and available as readline is (Real world example of thisproblem: Tclsh).
Smaller programs not using a configure script not supporting lineediting at all (A problem we had with Redis-cli for instance).
The result is a pollution of binaries without line editing support.
So Salvatore spent more or less two hours doing a reality checkresulting in this little library: is itreally needed for a lineediting library to be 20k lines of code? Apparently not, it is possibeto 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 thislittle library or just checking with configure if readline/libedit isavailable and resorting to linenoise if not.
Apparently almost every terminal you can happen to use today has somekind of support for basic VT100 escape sequences. So Salvatore triedto write a lib using just very basic VT100 features. The resultinglibrary appears to work everywhere Salvatore tried to use it, and nowcan work even on ANSI.SYS compatible terminals, since no VT220specific sequences are used anymore.
The original library has currently about 1100 lines of code. In orderto use it in your project just look at theexample.c file in thesource distribution, it is trivial. Linenoise is BSD code, so you canuse both in free software and commercial software.
- Linux text only console ($TERM = linux)
- Linux KDE terminal application ($TERM = xterm)
- Linux xterm ($TERM = xterm)
- Linux Buildroot ($TERM = vt100)
- 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)
- ANSI.SYS
- Emacs comint mode ($TERM = dumb)
- Windows
Please test it everywhere you can and report back!
Patches should be provided in the respect of linenoise sensibility forsmall and easy to understand code that and the licenserestrictions. Extensions must be submitted under a BSD license-style.A contributor license is required for contributions.
About
A small self-contained alternative to readline and libedit that supports UTF-8 and Windows and is BSD licensed.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- C++94.3%
- CMake3.0%
- C2.7%