REPL: inline output on same line as input (traditional Forth style)

Move cursor back to end of input line so output appears inline:
  > 2 2 + . 4  ok
instead of on a separate line.
This commit is contained in:
2026-04-12 17:28:06 +02:00
parent 7d2aba412b
commit f40b8cac21
+8 -4
View File
@@ -311,11 +311,15 @@ fn cmd_eval_or_repl(file: Option<&str>) -> anyhow::Result<()> {
match vm.evaluate(&line) { match vm.evaluate(&line) {
Ok(()) => { Ok(()) => {
let output = vm.take_output(); let output = vm.take_output();
if !output.is_empty() {
print!("{output}");
}
if !vm.is_compiling() { if !vm.is_compiling() {
println!(" ok"); // Move cursor back up to end of input line so
// output appears inline, like traditional Forth:
// > 2 2 + . 4 ok
let col = prompt.len() + line.len() + 1;
print!("\x1b[A\x1b[{col}G {output} ok");
println!();
} else if !output.is_empty() {
print!("{output}");
} }
} }
Err(e) => { Err(e) => {