aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 10ae251..50f4375 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,7 @@
8use std::f64; 8use std::f64;
9use std::borrow::Cow::{self,Owned}; 9use std::borrow::Cow::{self,Owned};
10use std::path::PathBuf; 10use std::path::PathBuf;
11use std::fs::create_dir_all;
11 12
12// modules 13// modules
13mod lex; 14mod lex;
@@ -30,6 +31,8 @@ use rustyline::highlight::Highlighter;
30use clap::{Arg, App}; 31use clap::{Arg, App};
31use lazy_static::lazy_static; 32use lazy_static::lazy_static;
32 33
34use directories::{ ProjectDirs, UserDirs };
35
33struct RLHelper { 36struct RLHelper {
34 completer: FilenameCompleter, 37 completer: FilenameCompleter,
35 highlighter: LineHighlighter, 38 highlighter: LineHighlighter,
@@ -131,14 +134,15 @@ fn main() {
131 hinter: AnswerHinter {} 134 hinter: AnswerHinter {}
132 }; 135 };
133 rl.set_helper(Some(h)); 136 rl.set_helper(Some(h));
134 let mut history_path = PathBuf::new(); 137
135 match dirs::home_dir() { 138 let eva_dirs = ProjectDirs::from("com", "NerdyPepper", "eva").unwrap();
136 Some(p) => { 139 let eva_data_dir = eva_dirs.data_dir();
137 history_path = p; 140 let mut history_path = PathBuf::from(eva_data_dir);
138 history_path.push("history.txt"); 141 match create_dir_all(eva_data_dir) {
139 }, 142 Ok(_) => history_path.push("history.txt"),
140 None => history_path.set_file_name("history.txt"), 143 Err(_) => history_path = PathBuf::from(UserDirs::new().unwrap().home_dir()),
141 }; 144 };
145
142 if rl.load_history(history_path.as_path()).is_err() { 146 if rl.load_history(history_path.as_path()).is_err() {
143 println!("No previous history.") 147 println!("No previous history.")
144 }; 148 };