Skip to content

Commit b1ae438

Browse files
committed
Add --always-readline and -n flags for character-mode REPL support
The LFE REPL uses character-at-a-time input mode, which requires rlwrap's --always-readline flag to work properly. Also added -n to suppress the warning about 'appears to do nothing'. This fixes the issue where rlwrap wasn't providing line editing because it detected the REPL was reading single keypresses.
1 parent 1832671 commit b1ae438

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/r3lfe_rlwrap.erl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ trampoline_via_rlwrap(State, Opts) ->
107107
%% Write a small shell script that will exec rlwrap
108108
%% This ensures rlwrap replaces the shell process and gets the TTY
109109
ScriptPath = "/tmp/rebar3_lfe_rlwrap_" ++ os:getpid() ++ ".sh",
110-
Script = "#!/bin/sh\nexec " ++ RlwrapCmd ++ "\n",
110+
%% Delete the script file before exec (it's already loaded into memory)
111+
Script = "#!/bin/sh\nrm -f " ++ ScriptPath ++ "\nexec " ++ RlwrapCmd ++ "\n",
111112

112113
ok = file:write_file(ScriptPath, Script),
113114
ok = file:change_mode(ScriptPath, 8#755),
@@ -117,21 +118,16 @@ trampoline_via_rlwrap(State, Opts) ->
117118
%% Execute the script using open_port with nouse_stdio
118119
%% This allows the child process to inherit stdin/stdout/stderr
119120
%% and interact directly with the terminal
120-
Port = erlang:open_port(
121+
_Port = erlang:open_port(
121122
{spawn, ScriptPath},
122-
[nouse_stdio, exit_status]
123+
[nouse_stdio]
123124
),
124125

125-
%% Wait for the script to complete
126-
receive
127-
{Port, {exit_status, Status}} ->
128-
file:delete(ScriptPath),
129-
erlang:halt(Status)
130-
after 60000 ->
131-
%% Timeout after 1 minute (shouldn't happen in normal use)
132-
file:delete(ScriptPath),
133-
erlang:halt(1)
134-
end.
126+
%% Don't wait for the port - just exit immediately
127+
%% This allows the spawned rlwrap/rebar3 process to take over the TTY
128+
%% The shell script will clean itself up when it exits
129+
timer:sleep(100), % Give the script a moment to start
130+
erlang:halt(0).
135131

136132
-spec get_rebar3_command() -> string().
137133
get_rebar3_command() ->
@@ -277,7 +273,9 @@ build_rlwrap_command(_State, Opts) ->
277273
%% "-p" ++ PromptColor, % Attach directly to avoid semicolon issues
278274
"-c", % Filename completion
279275
"-r", % Remember multi-line commands
280-
"-s", "10000" % History size
276+
"-s", "10000", % History size
277+
"--always-readline", % Required for REPLs that use character-at-a-time input
278+
"-n" % No warnings (silences the "appears to do nothing" warning)
281279
],
282280

283281
%% Add completion files that exist

0 commit comments

Comments
 (0)