Move hardcoded string file names into vars

This commit is contained in:
greg 2018-10-01 20:53:41 -07:00
parent a5c3c383dc
commit 1c11fec803

View File

@ -7,6 +7,9 @@ use itertools::Itertools;
use language::{ProgrammingLanguageInterface, EvalOptions, use language::{ProgrammingLanguageInterface, EvalOptions,
PassDebugOptionsDescriptor}; PassDebugOptionsDescriptor};
const HISTORY_SAVE_FILE: &'static str = ".schala_history";
const OPTIONS_SAVE_FILE: &'static str = ".schala_repl";
pub struct Repl { pub struct Repl {
options: EvalOptions, options: EvalOptions,
languages: Vec<Box<ProgrammingLanguageInterface>>, languages: Vec<Box<ProgrammingLanguageInterface>>,
@ -36,7 +39,7 @@ impl Repl {
} }
fn get_options() -> EvalOptions { fn get_options() -> EvalOptions {
File::open(".schala_repl") File::open(OPTIONS_SAVE_FILE)
.and_then(|mut file| { .and_then(|mut file| {
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents)?; file.read_to_string(&mut contents)?;
@ -50,14 +53,14 @@ impl Repl {
fn save_options(&self) { fn save_options(&self) {
let ref options = self.options; let ref options = self.options;
let read = File::create(".schala_repl") let read = File::create(OPTIONS_SAVE_FILE)
.and_then(|mut file| { .and_then(|mut file| {
let buf = ::serde_json::to_string(options).unwrap(); let buf = ::serde_json::to_string(options).unwrap();
file.write_all(buf.as_bytes()) file.write_all(buf.as_bytes())
}); });
if let Err(err) = read { if let Err(err) = read {
println!("Error saving .schala_repl file {}", err); println!("Error saving {} file {}", OPTIONS_SAVE_FILE, err);
} }
} }
@ -67,7 +70,7 @@ impl Repl {
println!("Schala MetaInterpreter version {}", ::VERSION_STRING); println!("Schala MetaInterpreter version {}", ::VERSION_STRING);
println!("Type {}help for help with the REPL", self.interpreter_directive_sigil); println!("Type {}help for help with the REPL", self.interpreter_directive_sigil);
self.line_reader.load_history(".schala_history").unwrap_or(()); self.line_reader.load_history(HISTORY_SAVE_FILE).unwrap_or(());
loop { loop {
let language_name = self.get_cur_language().get_language_name(); let language_name = self.get_cur_language().get_language_name();
@ -96,7 +99,7 @@ impl Repl {
} }
} }
} }
self.line_reader.save_history(".schala_history").unwrap_or(()); self.line_reader.save_history(HISTORY_SAVE_FILE).unwrap_or(());
self.save_options(); self.save_options();
println!("Exiting..."); println!("Exiting...");
} }