aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-06-24 17:32:31 +0100
committerNerdyPepper <[email protected]>2019-06-24 17:32:31 +0100
commit7835955bd9822a2fe49f70d05827fc3839f7d59e (patch)
tree181f5afaf9783afe026bf2c43ff09a3c14d540ec
parentd2d80030c1eaae9f08fb6a51c4159eed009086b6 (diff)
use better directory crate, use data_dir for history
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs18
2 files changed, 12 insertions, 8 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1aafe11..25b849f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,4 +16,4 @@ rustyline = "4.1.0"
16clap = "2.32.0" 16clap = "2.32.0"
17radix_fmt = "1.0.0" 17radix_fmt = "1.0.0"
18lazy_static = "1.3.0" 18lazy_static = "1.3.0"
19dirs = "2.0.1" 19directories = "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 @@
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 };