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
+10
View File
@@ -425,12 +425,22 @@ fn run_repl(vm: &mut ForthVM<NativeRuntime>) -> anyhow::Result<()> {
}
let output = output.replace('\x0C', "");
if !vm.is_compiling() {
if output.contains('\n') {
// Multi-line output (DUMP, WORDS, ...):
// print as a block, then ok on its own line
print!("{output}");
if !output.ends_with('\n') {
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() {
print!("{output}");
}