Skip to content

Commit

Permalink
Add support for history
Browse files Browse the repository at this point in the history
  • Loading branch information
dubrowgn committed Jul 15, 2017
1 parent 2c23ec8 commit b215c01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ include = [

[dependencies]
getopts = "0.2.14"
rustyline = "1.0.0"
#rustyline = { path = "../rustyline" }
rustyline = { git = "https://github.com/dubrowgn/rustyline", branch = "tcalc" }
#rustyline = { git = "https://github.com/dubrowgn/rustyline", branch = "tcalc" }

[features]
trace = []
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ fn repl() {
let mut runner = Runner::new();
let mut rl = Editor::<()>::new();

let history_path = match env::home_dir() {
Some(mut home_dir) => {
home_dir.push(".tcalc_history");
Some(home_dir)
},
_ => None
};

if let Some(ref path) = history_path {
match rl.load_history(&path) { _ => { } }
}

loop {
match rl.readline("> ") {
Ok(line) => {
Expand All @@ -86,10 +98,14 @@ fn repl() {
} // match
},
Err(ReadlineError::Interrupted) => { },
Err(ReadlineError::Eof) => { },
Err(ReadlineError::Eof) => break,
Err(msg) => println!("error: {}", msg),
} // match
} // loop

if let Some(ref path) = history_path {
match rl.save_history(&path) { _ => { } }
}
} // repl

fn main() {
Expand Down

0 comments on commit b215c01

Please sign in to comment.