From 2910884b83e7db7bec98b2f57f309e35429488b5 Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk <201152+ok2@users.noreply.github.com> Date: Wed, 5 Aug 2026 16:07:10 +0200 Subject: [PATCH] fix(repl): multi-line output starts on its own line, inline ok only for single-line --- crates/cli/src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 4b5bd2a..1060033 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -425,12 +425,22 @@ fn run_repl(vm: &mut ForthVM) -> anyhow::Result<()> { } let output = output.replace('\x0C', ""); if !vm.is_compiling() { - // 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!(); + 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}"); }