Skip to content

Commit

Permalink
Don't run empty commands (including comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
ageron committed Aug 1, 2024
1 parent 7992d99 commit 2cc8790
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/repl_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,25 @@ pub fn main() -> i32 {
loop {
match editor.readline(PROMPT) {
Ok(line) => {
let line = line.trim();
let line = line.trim_end();
if line.trim().is_empty() {
// empty lines are ignored
println!();
continue;
}

editor.add_history_entry(line);

if line
.lines()
.map(|ln| ln.trim())
.all(|ln| ln.is_empty() || ln.starts_with("#"))
{
// if there are only whitespaces and comments, don't run it
println!();
continue;
}

let repl_state = &mut editor
.helper_mut()
.expect("Editor helper was not set")
Expand Down

0 comments on commit 2cc8790

Please sign in to comment.