Actually I can’t rely on it, all that’s in the command history is whatever was typed into the prolog top level. A call to el_add_history
addresses that, thanks for the pointer to editline
, I don’t think I would have found it otherwise.
Thanks. I was wondering how to do that.
Bash glues continuation lines into one long line in its history, the SWI top-level also accepts \
continuation lines but preserves the \
+ linebreak, That’s ideal but looks like it might be a bit of a faff to do so I’ve just done “glue all the lines together in the history” as it’s trivial to do. Here’s what I ended up with:
repl(Action) :-
prompt(P, 'p2k> '),
readContLines([], RevLines),
prompt(_, P),
foldl(string_concat, RevLines, "", Line),
el_add_history(user_input, Line),
call(Action, Line),
repl(Action)
.
readContLines(PrevLines, Lines) :-
read_line_to_string(user_input, Line),
Line \= end_of_file, Line \= "exit",
(
sub_string(Line, Pos, 1, 0, "\\")
->
sub_string(Line, 0, Pos, 1, L1),
readContLines([L1 | PrevLines], Lines)
;
Lines = [Line | PrevLines]
)
.