Skip to content

Commit

Permalink
[Cider 2] Fix explain string + add little message on repeated command…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
EclecticGriffin committed Jul 18, 2024
1 parent d1a2b96 commit 757d77f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion interp/src/debugger/commands/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
20 changes: 17 additions & 3 deletions interp/src/debugger/debugger_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,29 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
"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),
Expand Down Expand Up @@ -289,7 +303,7 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
}

Command::Explain => {
print!("{}", Command::get_explain_string().blue())
print!("{}", Command::get_explain_string())
}

Command::Restart => {
Expand Down Expand Up @@ -342,7 +356,7 @@ impl<C: AsRef<Context> + Clone> Debugger<C> {
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(
Expand Down

0 comments on commit 757d77f

Please sign in to comment.