diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/main.rs | 18 |
2 files changed, 12 insertions, 8 deletions
@@ -16,4 +16,4 @@ rustyline = "4.1.0" | |||
16 | clap = "2.32.0" | 16 | clap = "2.32.0" |
17 | radix_fmt = "1.0.0" | 17 | radix_fmt = "1.0.0" |
18 | lazy_static = "1.3.0" | 18 | lazy_static = "1.3.0" |
19 | dirs = "2.0.1" | 19 | directories = "2.0.1" |
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 @@ | |||
8 | use std::f64; | 8 | use std::f64; |
9 | use std::borrow::Cow::{self,Owned}; | 9 | use std::borrow::Cow::{self,Owned}; |
10 | use std::path::PathBuf; | 10 | use std::path::PathBuf; |
11 | use std::fs::create_dir_all; | ||
11 | 12 | ||
12 | // modules | 13 | // modules |
13 | mod lex; | 14 | mod lex; |
@@ -30,6 +31,8 @@ use rustyline::highlight::Highlighter; | |||
30 | use clap::{Arg, App}; | 31 | use clap::{Arg, App}; |
31 | use lazy_static::lazy_static; | 32 | use lazy_static::lazy_static; |
32 | 33 | ||
34 | use directories::{ ProjectDirs, UserDirs }; | ||
35 | |||
33 | struct RLHelper { | 36 | struct 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 | }; |