Switch to rustyline library
This commit is contained in:
parent
55e372a670
commit
69200048fa
@ -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"
|
||||
|
@ -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<Box<ProgrammingLanguageInte
|
||||
}
|
||||
}
|
||||
|
||||
type LineReader = linefeed::Reader<linefeed::terminal::DefaultTerminal>;
|
||||
struct Repl {
|
||||
options: EvalOptions,
|
||||
languages: Vec<Box<ProgrammingLanguageInterface>>,
|
||||
current_language_index: usize,
|
||||
interpreter_directive_sigil: char,
|
||||
reader: LineReader,
|
||||
console: rustyline::Editor<()>,
|
||||
}
|
||||
|
||||
impl Repl {
|
||||
fn new(languages: Vec<Box<ProgrammingLanguageInterface>>, 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");
|
||||
|
Loading…
Reference in New Issue
Block a user