aboutsummaryrefslogtreecommitdiff
path: root/src/readline/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/readline/mod.rs')
-rw-r--r--src/readline/mod.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/readline/mod.rs b/src/readline/mod.rs
index 8eedbfa..ea195ee 100644
--- a/src/readline/mod.rs
+++ b/src/readline/mod.rs
@@ -20,18 +20,18 @@ pub struct RLHelper {
20 hinter: HistoryHinter, 20 hinter: HistoryHinter,
21} 21}
22 22
23struct LineHighlighter { } 23struct LineHighlighter {}
24impl Highlighter for LineHighlighter { 24impl Highlighter for LineHighlighter {
25 fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { 25 fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
26 Owned(format!("\x1b[90m{}\x1b[0m", hint)) 26 Owned(format!("\x1b[90m{}\x1b[0m", hint))
27 } 27 }
28 fn highlight<'l>(&self, line: &'l str, _: usize) -> Cow<'l, str> { 28 fn highlight<'l>(&self, line: &'l str, _: usize) -> Cow<'l, str> {
29 use std::io::{ BufReader, BufRead };
30 use std::fs::OpenOptions; 29 use std::fs::OpenOptions;
30 use std::io::{BufRead, BufReader};
31 31
32 let eva_dirs = ProjectDirs::from("com", "NerdyPepper", "eva").unwrap(); 32 let eva_dirs = ProjectDirs::from("com", "NerdyPepper", "eva").unwrap();
33 let eva_data_dir = eva_dirs.data_dir(); 33 let eva_data_dir = eva_dirs.data_dir();
34 let mut previous_ans_path= PathBuf::from(eva_data_dir); 34 let mut previous_ans_path = PathBuf::from(eva_data_dir);
35 previous_ans_path.push("previous_ans.txt"); 35 previous_ans_path.push("previous_ans.txt");
36 36
37 let file = OpenOptions::new() 37 let file = OpenOptions::new()
@@ -43,11 +43,10 @@ impl Highlighter for LineHighlighter {
43 43
44 let rdr = BufReader::new(file); 44 let rdr = BufReader::new(file);
45 let lines = rdr.lines().map(|l| l.unwrap()); 45 let lines = rdr.lines().map(|l| l.unwrap());
46 let prev_ans = lines 46 let prev_ans = match lines.last() {
47 .last() 47 Some(val) => val.parse::<f64>().ok(),
48 .unwrap() 48 None => None,
49 .parse::<f64>() 49 };
50 .ok();
51 let op = eval_math_expression(line, prev_ans); 50 let op = eval_math_expression(line, prev_ans);
52 match op { 51 match op {
53 Ok(_) => { 52 Ok(_) => {
@@ -114,7 +113,7 @@ pub fn create_readline() -> Editor<RLHelper> {
114 let mut rl = Editor::with_config(config); 113 let mut rl = Editor::with_config(config);
115 let h = RLHelper { 114 let h = RLHelper {
116 completer: FilenameCompleter::new(), 115 completer: FilenameCompleter::new(),
117 highlighter: LineHighlighter { }, 116 highlighter: LineHighlighter {},
118 hinter: HistoryHinter {}, 117 hinter: HistoryHinter {},
119 }; 118 };
120 rl.set_helper(Some(h)); 119 rl.set_helper(Some(h));