From 0581d0a2e184f93ddfe55a9fac9aba7cd59e0273 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Thu, 13 Oct 2022 19:58:02 +0200 Subject: [PATCH] =?UTF-8?q?Improve=20the=20repl=20=F0=9F=A5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/repl/impl_repl.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/repl/impl_repl.rs b/src/repl/impl_repl.rs index 88f0f5c..acf06f2 100644 --- a/src/repl/impl_repl.rs +++ b/src/repl/impl_repl.rs @@ -102,11 +102,14 @@ impl Repl { } pub fn process(&mut self, mut user_input: String) { + let mut print = false; user_input.chars().for_each(|ch| { if ch == '[' { self.loop_depth += 1; } else if ch == ']' { self.loop_depth -= 1; + } else if ch == '.' { + print = true; } }); match user_input.find('[') { @@ -143,6 +146,9 @@ impl Repl { match self.interpreter.run(user_input) { Ok(_) => { info!("Successfully ran brainfuck source code from REPL"); + if print { + println!(); // Print newline after output, if user requested print any output + } } Err(e) => { error!("Failed to run brainfuck source code from REPL: {}", e);