From 16fdf37ba3f0bcf04e81a68b3db0ff9fc1cf4c4f Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 2 Feb 2019 01:00:09 -0800 Subject: [PATCH] A solution for multiline entry I don't really like this... --- schala-repl/src/repl/mod.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/schala-repl/src/repl/mod.rs b/schala-repl/src/repl/mod.rs index bb09531..f18bac5 100644 --- a/schala-repl/src/repl/mod.rs +++ b/schala-repl/src/repl/mod.rs @@ -99,6 +99,7 @@ impl Repl { } fn input_loop(&mut self, input: String) { + use linefeed::ReadResult; if input == "" { return; } @@ -110,8 +111,26 @@ impl Repl { return; } - let output = self.input_handler(&input); - self.line_reader.add_history_unique(input.clone()); + let mut lines = input; + self.line_reader.set_prompt("> ").unwrap(); + + loop { + match self.line_reader.read_line() { + Err(e) => { + println!("Terminal read error: {}", e); + return; + }, + Ok(ReadResult::Eof) => break, + Ok(ReadResult::Signal(_)) => break, + Ok(ReadResult::Input(input)) => { + lines.push('\n'); //TODO not sure if this is needed? + lines.push_str(&input); + } + } + } + + self.line_reader.add_history_unique(lines.clone()); + let output = self.input_handler(&lines); println!("=> {}", output); }