Closed TeamSPoon closed 1 week ago
If I were addressing the REPL prompt overwrite issue and history management, I would start by building a minimal echo REPL in SWI-Prolog to better understand and test input handling, cursor management, and history behavior. This approach allows for isolated debugging and ensures clean integration back into the larger system.
Starting with a simple echo REPL that reads user input, echoes it back, and loops until you exit:
% A minimal echo REPL in SWI-Prolog with setup_call_cleanup/3 for prompt management
repl :-
setup_call_cleanup(
prompt(WAS,'REPL> '),
run_repl,
prompt(_,WAS)
).
run_repl :-
repeat,
read_input(Line),
handle_input(Line),
Line == "exit".
read_input(Line) :-
read_line_to_string(user_input, Line).
handle_input("exit") :- !.
handle_input(Line) :-
format("You typed: ~w~n", [Line]),
fail. % Fail to loop back to repeat/0
% Start the REPL
:- repl.
Setup and Cleanup with setup_call_cleanup/3
:
'REPL> '
).?-
) when the REPL ends.Repeat Loop with User Input Handling:
fail
ensures the loop continues unless "exit" is entered.maybe for https://github.com/trueagi-io/metta-wam/issues/91
handle_input(Line) :-
(Line \== "exit" -> readline:add_history(Line) ; true),
format("You typed: ~w~n", [Line]),
fail.
You can load and save history across sessions like this:
:- initialization(load_history).
:- at_halt(save_history).
load_history :-
readline:read_history('~/.config/metta/repl_history.txt').
save_history :-
readline:write_history('~/.config/metta/repl_history.txt').
This minimal REPL is a good environment to test:
@TeamSPoon opened the bug, @royward fixed it. I confirm the fix for me worked. @drspro needed it as badly as I did (well everyone did). If it works for him, he can close the issue.
Closing - good fix - i think we are all good
In the MeTTaLog REPL, there is an issue where the prompt can be overwritten at unpredictable times. This often occurs when using the left arrow key to navigate back toward the prompt or when pasting text into the REPL. The result is that the prompt becomes partially or fully erased, leading to a confusing and inconsistent user experience.
Steps to Reproduce:
Expected Behavior:
Actual Behavior:
Priority and Impact:
This issue affects the usability of the REPL, particularly when pasting text or editing input. The inconsistent nature of the problem makes it more frustrating for users, as they may not be able to predict when the prompt will be affected. While it doesn’t cause crashes or data loss, it significantly impacts the user experience and makes the REPL harder to use during complex interactions.