Skip to content

Commit 16957ec

Browse files
committed
Ignore empty commands in the REPL
1 parent 034d149 commit 16957ec

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Diff for: crates/repl_cli/src/lib.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,25 @@ pub fn main() -> i32 {
5252
loop {
5353
match editor.readline(PROMPT) {
5454
Ok(line) => {
55-
let line = line.trim();
55+
let line = line.trim_end();
56+
if line.trim().is_empty() {
57+
// empty lines are ignored
58+
println!();
59+
continue;
60+
}
5661

5762
editor.add_history_entry(line);
5863

64+
if line
65+
.lines()
66+
.map(|ln| ln.trim())
67+
.all(|ln| ln.is_empty() || ln.starts_with('#'))
68+
{
69+
// if there are only whitespaces and comments, don't run it
70+
println!();
71+
continue;
72+
}
73+
5974
let repl_state = &mut editor
6075
.helper_mut()
6176
.expect("Editor helper was not set")

0 commit comments

Comments
 (0)