From ad450469a5fa6b86cb8c7ae068ee1bdc04c99659 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 1 Mar 2018 02:43:11 -0800 Subject: [PATCH] Switch to rustyline library --- schala-lib/Cargo.toml | 2 +- schala-lib/src/lib.rs | 30 ++++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/schala-lib/Cargo.toml b/schala-lib/Cargo.toml index 0352761..49fd64a 100644 --- a/schala-lib/Cargo.toml +++ b/schala-lib/Cargo.toml @@ -8,7 +8,6 @@ llvm-sys = "*" take_mut = "0.1.3" itertools = "0.5.8" getopts = "*" -linefeed = "0.3" lazy_static = "0.2.8" maplit = "*" colored = "1.5" @@ -20,6 +19,7 @@ rocket_codegen = "0.3.5" rocket_contrib = "0.3.5" phf = "0.7.12" includedir = "0.2.0" +rustyline = "1.0.0" [build-dependencies] includedir_codegen = "0.2.0" diff --git a/schala-lib/src/lib.rs b/schala-lib/src/lib.rs index a898323..807ed9e 100644 --- a/schala-lib/src/lib.rs +++ b/schala-lib/src/lib.rs @@ -3,7 +3,7 @@ #![feature(plugin)] #![plugin(rocket_codegen)] extern crate getopts; -extern crate linefeed; +extern crate rustyline; extern crate itertools; #[macro_use] extern crate lazy_static; @@ -23,6 +23,9 @@ use std::io::{Read, Write}; use std::process::exit; use std::default::Default; +use rustyline::error::ReadlineError; +use rustyline::Editor; + mod language; mod webapp; pub mod llvm_wrap; @@ -112,26 +115,26 @@ fn run_noninteractive(filename: &str, languages: Vec; struct Repl { options: EvalOptions, languages: Vec>, current_language_index: usize, interpreter_directive_sigil: char, - reader: LineReader, + console: rustyline::Editor<()>, } impl Repl { fn new(languages: Vec>, initial_index: usize) -> Repl { - let reader: linefeed::Reader<_> = linefeed::Reader::new("Metainterpreter").unwrap(); let i = if initial_index < languages.len() { initial_index } else { 0 }; + let console = Editor::<()>::new(); + Repl { options: Repl::get_options(), languages: languages, current_language_index: i, interpreter_directive_sigil: '.', - reader: reader, + console } } @@ -162,23 +165,19 @@ impl Repl { } fn run(&mut self) { - use linefeed::ReadResult::*; println!("MetaInterpreter v 0.05"); loop { let language_name = self.languages[self.current_language_index].get_language_name(); let prompt_str = format!("{} >> ", language_name); - self.reader.set_prompt(&prompt_str); - match self.reader.read_line() { + match self.console.readline(&prompt_str) { + Err(ReadlineError::Eof) | Err(ReadlineError::Interrupted) => break, Err(e) => { println!("Terminal read error: {}", e); }, - Ok(Eof) => { - break; - } - Ok(Input(ref input)) => { - self.reader.add_history(input.clone()); + Ok(ref input) => { + self.console.add_history_entry(input); if self.handle_interpreter_directive(input) { continue; } @@ -222,11 +221,6 @@ impl Repl { self.save_options(); exit(0) }, - "history" => { - for item in self.reader.history() { - println!("{}", item); - } - }, "help" => { println!("Commands:"); println!("exit | quit");