From 2cc8790c2e067015ae1f67369fd7a0833f585cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Thu, 1 Aug 2024 12:26:09 +1200 Subject: [PATCH] Don't run empty commands (including comments) --- crates/repl_cli/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/repl_cli/src/lib.rs b/crates/repl_cli/src/lib.rs index 08ee592498e..fca3ac215f8 100644 --- a/crates/repl_cli/src/lib.rs +++ b/crates/repl_cli/src/lib.rs @@ -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")