fix(repl): multi-line output starts on its own line, inline ok only for single-line

This commit is contained in:
Oleksandr Kozachuk
2026-08-05 16:07:10 +02:00
parent f584066a0a
commit 2910884b83
+16 -6
View File
@@ -425,12 +425,22 @@ fn run_repl(vm: &mut ForthVM<NativeRuntime>) -> anyhow::Result<()> {
} }
let output = output.replace('\x0C', ""); let output = output.replace('\x0C', "");
if !vm.is_compiling() { if !vm.is_compiling() {
// Move cursor back up to end of input line so if output.contains('\n') {
// output appears inline, like traditional Forth: // Multi-line output (DUMP, WORDS, ...):
// > 2 2 + . 4 ok // print as a block, then ok on its own line
let col = prompt.len() + line.len() + 1; print!("{output}");
print!("\x1b[A\x1b[{col}G {output} ok"); if !output.ends_with('\n') {
println!(); println!();
}
println!(" ok");
} else {
// 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() { } else if !output.is_empty() {
print!("{output}"); print!("{output}");
} }