Move linefeed reader to struct
This commit is contained in:
parent
b04a8f0092
commit
4eb7683f47
21
src/main.rs
21
src/main.rs
@ -85,35 +85,34 @@ fn run_noninteractive(filename: &str, compile: bool, trace_evaluation: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LineReader = linefeed::Reader<linefeed::terminal::DefaultTerminal>;
|
||||||
struct Repl<'a> {
|
struct Repl<'a> {
|
||||||
show_tokens: bool,
|
show_tokens: bool,
|
||||||
show_parse: bool,
|
show_parse: bool,
|
||||||
show_eval: bool,
|
show_eval: bool,
|
||||||
input_history: Vec<String>,
|
|
||||||
output_history: Vec<String>,
|
|
||||||
evaluator: Evaluator<'a>,
|
evaluator: Evaluator<'a>,
|
||||||
interpreter_directive_sigil: char,
|
interpreter_directive_sigil: char,
|
||||||
|
reader: LineReader,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Repl<'a> {
|
impl<'a> Repl<'a> {
|
||||||
fn new(trace_evaluation: bool) -> Repl<'a> {
|
fn new(trace_evaluation: bool) -> Repl<'a> {
|
||||||
|
let mut reader: linefeed::Reader<_> = linefeed::Reader::new("").unwrap();
|
||||||
|
reader.set_prompt(">> ");
|
||||||
Repl {
|
Repl {
|
||||||
show_tokens: false,
|
show_tokens: false,
|
||||||
show_parse: false,
|
show_parse: false,
|
||||||
show_eval: false,
|
show_eval: false,
|
||||||
input_history: vec![],
|
|
||||||
output_history: vec![],
|
|
||||||
evaluator: Evaluator::new_with_opts(None, trace_evaluation),
|
evaluator: Evaluator::new_with_opts(None, trace_evaluation),
|
||||||
interpreter_directive_sigil: '.',
|
interpreter_directive_sigil: '.',
|
||||||
|
reader: reader,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn run(&mut self) {
|
fn run(&mut self) {
|
||||||
use linefeed::ReadResult::*;
|
use linefeed::ReadResult::*;
|
||||||
println!("Schala v 0.02");
|
println!("Schala v 0.02");
|
||||||
let mut reader = linefeed::Reader::new("oi").unwrap();
|
|
||||||
reader.set_prompt(">> ");
|
|
||||||
loop {
|
loop {
|
||||||
match reader.read_line() {
|
match self.reader.read_line() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Terminal read error: {:?}", e);
|
println!("Terminal read error: {:?}", e);
|
||||||
break;
|
break;
|
||||||
@ -183,16 +182,8 @@ impl<'a> Repl<'a> {
|
|||||||
match cmd {
|
match cmd {
|
||||||
"exit" | "quit" => process::exit(0),
|
"exit" | "quit" => process::exit(0),
|
||||||
"history" => {
|
"history" => {
|
||||||
println!("history:");
|
|
||||||
for cmd in self.input_history.iter() {
|
|
||||||
println!("{}", cmd);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"output_history" => {
|
"output_history" => {
|
||||||
println!("output history:");
|
|
||||||
for cmd in self.output_history.iter() {
|
|
||||||
println!("{}", cmd);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
self.update_state(&commands);
|
self.update_state(&commands);
|
||||||
|
Loading…
Reference in New Issue
Block a user