Open arbipher opened 2 years ago
As a comparison, utop
which is based on lambda_term
doesn't have this problem, .e.g
utop # print_endline "\n42\n";;
42
- : unit = ()
To make utop err (I did it for debug my reply), printing sth after it reads user input before flush the buffer at line 827 of uTop_main.ml
e.g. ((fun () -> print_endline "suffix\n"; LTerm.flush term)
). Now utop also prints my input print_endline "\n42\n";;
again and then do the execution.
utop # print_endline "\n42\nsuffix
─( 12:22:07 )─< command 1 >─────────────────────────────────────────────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # print_endline "\n42\n";;
42
- : unit = ()
I could also guess the reason in the redraw logic of LTerm.read_line
on this input line is triggered when extra output is put here.
I am working on my repl based on examples/repl.ml. A common scenario is e.g.
Interpreter.eval
prints something to the stdout.This will make the
LTerm_read_line
behave strange (though reasonable). It will write the user input line again and line border ifshow_box
is set true e.g.The original example prints like this when my input is
1 1 (Enter)
.My expected restult is
The problem can be fixed by adding a flush in the main loop of the example
My point to make the issue is I think it may be better to flush the stdout inside
src/lterm_read_line.ml
when it accepts user input when pressing enter (or ^M). There areLTerm.flush term
in the code when handling other cases.