Can rlwrap use a wrapped command's own TAB completion?
Asked Answered
K

2

13

I want to use rlwrap with a custom erlang repl.

It works perfectly if I run it as "rlwrap -a myrepl".

The problem is that myrepl has builtin tab completion which gets trampled by rlwrap.

I want to make rlwrap to release the TAB key

Kizzie answered 9/2, 2012 at 12:35 Comment(2)
What is myrepl? Is this an erlang question or a perl/rlwrap question?Amu
For me benefits of using rlwrap are greater than the value of Erlang autocomplete. I couldn't make them work together, so I use "rlwrap erl -oldshell".Register
A
23

You can't use rlwrap's line editing/history and your repl's TAB completion at the same time.

rlwrap provides line editing, history and (very simple) completion for commands that don't have it. A command that has something as fancy as TAB completion shouldn't need rlwrap to do its line editing, should it?

The -a (--always-readline) option is a rather crude way to substitute rlwrap's line editing behaviour for that of your command. It is primarily meant for commands that have a very simple line editor, without e.g. command history

If you want to use the -a option because you prefer rlwrap's fanciness (like persistent history, or coloured prompts) to your command's (like TAB completion), go ahead, but it is impossible to pick some fanciness of one and keep some of the other.

This is the (small) price programs (and their users) have to pay for avoiding the readline library and the GPL license that comes with it.

Hans (rlwrap author)


Edit (April 2017):

In many cases it will be possible to use a filter to restore completion. See A node shell based on readline for an example of this.

Additive answered 9/2, 2012 at 21:50 Comment(5)
The Erlang shell has TAB completion, but lacks in several other areas. No history between sessions, limited line editing capabilities etc.Bufflehead
@Hans do you see any reasons why, if I change rlwrap's source and remove the TAB from the special keys or maybe rewire it to some other key, I won't get this to work? Haven't had time to try, but I'm taking advantage that you answered my post.Kizzie
@ Gabriel: Removing TAB from the "special keys" is not enough, this will only give you a dead TAB key. What really needs to be done is that the TAB clears the input buffer of the underlying command, passes the current readline input buffer to it, positions its cursor, then passes the TAB, parses the resulting output (including cursor movement commands), and finally fills the readline input buffer and sets rl_point accordingly. All of these steps are difficult and error-prone; especially the parsing of your command's output would require rlwrap to contain a virtual terminal emulator.Additive
@HansLub thanks for clearing that up. I'll mark this as solved. Would've upvoted you but I don't have enough reputation yet.Kizzie
Shame, I wanted to use rlwrap to get vim bindings into an elixir repl. Guess I'll just use it from within emacs instead. Thanks for the concise explanation.Ealasaid
O
2

Rlwrap is cute. But in Erlang, it only offers persistent history while breaking erl's tab completion.

The fundamental issue is Erlang's erl REPL is just old and busted, and doesn't follow normal *nix conventions. Furthermore, they refuse to fix it because of fear of random, grouchy sysadmins whom can't accept any changes. No amount of rlwrap "duct-tape" hacks can fix a poor UX REPL.

It would be better (though significantly more work) to write a REPL from scratch like pry/ipython/etc. that does configurable color, tab completion, persistent history, paging, CLI observer, plugins, etc.

Rlwrap shines on programs with primitive shells.

Olethea answered 13/4, 2017 at 0:40 Comment(1)
I think you are being too harsh on "random, grouchy sysadmins", and overestimating the difficulty of using the excellent readline library. The main reason for those old and busted REPLs is readlines GPL license: using readline means that your program has to be GPL. See this email exchange from a quarter century ago - probably one of the first cases of GPL enforcement, in which readline played a key role.Additive

© 2022 - 2024 — McMap. All rights reserved.