lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jul 28, 2017, at 8:48 PM, Jay Carlson <nop@nop.com> wrote:

> As a bonus, repl-readline.so can be installed anywhere in cpath, 

More generally, repl-readline can be anywhere require() can find it, including placing it in package.preload["repl-readline"]. This allows people who don't want dynamic loading to keep the option of readline support.

The usual alternative to libreadline and libedit is linenoise. (https://github.com/antirez/linenoise). Linenoise has the advantage of no external dependencies besides POSIX libc, so presumably you'd just compile linenoise into repl-readline.so directly. But Linenoise has the near-fatal flaw that it does not support reverse-history-search.[1] (I hit Ctrl-R *really often*.) Lack of history search is fixed in Linenoise NG, which has the same C API and supports Windows. Internally, it uses C++ though.

Linenoise did the hard work of compatibility-testing terminal control sequences. If a Lua extension provides the POSIX termios raw IO stuff, I don't see why somebody ambitious couldn't write the whole thing in Lua. (Maybe it should run in a separate Lua state?)

Jay

[1]: Here's what busybox describes for reverse search. From https://git.busybox.net/busybox/tree/libbb/lineedit.c#n2123 :

/* Mimic readline Ctrl-R reverse history search.
 * When invoked, it shows the following prompt:
 * (reverse-i-search)'': user_input [cursor pos unchanged by Ctrl-R]
 * and typing results in search being performed:
 * (reverse-i-search)'tmp': cd /tmp [cursor under t in /tmp]
 * Search is performed by looking at progressively older lines in history.
 * Ctrl-R again searches for the next match in history.
 * Backspace deletes last matched char.
 * Control keys exit search and return to normal editing (at current history line).
 */