Have the repl loop

This commit is contained in:
Richard Feldman 2020-04-18 16:02:33 -04:00
parent a99a339672
commit c9ef2deb80

View File

@ -38,26 +38,38 @@ pub fn main() -> io::Result<()> {
use std::io::BufRead; use std::io::BufRead;
println!( println!(
"\n The rockin \u{001b}[36mroc repl\u{001b}[0m\n\u{001b}[35m────────────────────────\n" "\n The rockin \u{001b}[36mroc repl\u{001b}[0m\n\u{001b}[35m────────────────────────\u{001b}[0m\n\nEnter :help for help, or :exit to exit."
); );
// Loop // Loop
print!("\u{001b}[36m▶\u{001b}[0m "); loop {
print!("\n\u{001b}[36m▶\u{001b}[0m ");
io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
let stdin = io::stdin(); let stdin = io::stdin();
let line = stdin let line = stdin
.lock() .lock()
.lines() .lines()
.next() .next()
.expect("there was no next line") .expect("there was no next line")
.expect("the line could not be read"); .expect("the line could not be read");
let (answer, answer_type) = gen(line.as_str(), Triple::host(), OptLevel::Normal); match line.trim() {
":help" => {
println!("Use :exit to exit.");
}
":exit" => {
break;
}
line => {
let (answer, answer_type) = gen(line, Triple::host(), OptLevel::Normal);
println!("\n{} \u{001b}[35m:\u{001b}[0m {}", answer, answer_type); println!("\n{} \u{001b}[35m:\u{001b}[0m {}", answer, answer_type);
}
}
}
Ok(()) Ok(())
} }