From 757d77fc1867bf20ff6c98c20fdf2db4ab2c45a8 Mon Sep 17 00:00:00 2001 From: Griffin Berlstein Date: Thu, 18 Jul 2024 15:29:48 -0400 Subject: [PATCH] [Cider 2] Fix explain string + add little message on repeated command errors (#2214) tiny patch to fix some printing and add a (hopefully helpful) message when an invalid command is given 3 times in a row --- interp/src/debugger/commands/core.rs | 2 +- interp/src/debugger/debugger_core.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/interp/src/debugger/commands/core.rs b/interp/src/debugger/commands/core.rs index 6765ca8a23..0d40119743 100644 --- a/interp/src/debugger/commands/core.rs +++ b/interp/src/debugger/commands/core.rs @@ -380,7 +380,7 @@ lazy_static! { // print-state CIBuilder::new().invocation("print-state") .description("Print the internal state of the target cell. Takes an optional print code before the target") - .usage("> watch after GROUP with print-state \\s mem").build(), + .usage("> print-state \\s mem").build(), // watch CIBuilder::new().invocation("watch") .description("Watch a given group with a print statement. Takes an optional position (before/after)") diff --git a/interp/src/debugger/debugger_core.rs b/interp/src/debugger/debugger_core.rs index 3c06257966..230f67d136 100644 --- a/interp/src/debugger/debugger_core.rs +++ b/interp/src/debugger/debugger_core.rs @@ -207,15 +207,29 @@ impl + Clone> Debugger { "r".underline() ); + let mut err_count = 0_u8; + while !self.interpreter.is_done() { let comm = input_stream.next_command(); let comm = match comm { - Ok(c) => c, + Ok(c) => { + err_count = 0; + c + } Err(e) => match *e { InterpreterError::InvalidCommand(_) | InterpreterError::UnknownCommand(_) | InterpreterError::ParseError(_) => { println!("Error: {}", e.red().bold()); + err_count += 1; + if err_count == 3 { + println!( + "Type {} for a list of commands or {} for usage examples.", + "help".yellow().bold().underline(), + "explain".yellow().bold().underline() + ); + err_count = 0; + } continue; } _ => return Err(e), @@ -289,7 +303,7 @@ impl + Clone> Debugger { } Command::Explain => { - print!("{}", Command::get_explain_string().blue()) + print!("{}", Command::get_explain_string()) } Command::Restart => { @@ -342,7 +356,7 @@ impl + Clone> Debugger { return Ok(DebuggerReturnStatus::Exit); } Command::Explain => { - print!("{}", Command::get_explain_string().blue().bold()) + print!("{}", Command::get_explain_string()) } Command::Restart => { return Ok(DebuggerReturnStatus::Restart(Box::new(