Timothee Cour 8535b26a75 docs now show nimExperimentalX APIs (#18345) | hace 3 años | |
---|---|---|
.. | ||
LICENSE.txt | hace 9 años | |
README.markdown | hace 9 años | |
linenoise.c | hace 3 años | |
linenoise.h | hace 3 años | |
linenoise.nim | hace 3 años |
A minimal, zero-config, BSD licensed, readline replacement used in Redis, MongoDB, and Android.
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?
So what usually happens is either:
The result is a pollution of binaries without line editing support.
So 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.
Apparently 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 VT220 specific sequences are used anymore.
The 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.
Please test it everywhere you can and report back!
Patches should be provided in the respect of linenoise sensibility for small easy to understand code.
Send feedbacks to antirez at gmail