Fixing history

- Histroy was loaded from correct but saved in wrong file
- Somehow multiline string only works while loading files (not bad)
- Fixing error on not-ended string: unrecoverable

Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
teo3300
2024-01-17 17:32:13 +09:00
parent 6eed79557f
commit 4c55c9219f
2 changed files with 4 additions and 3 deletions

View File

@ -69,11 +69,12 @@ use rustyline::DefaultEditor;
pub fn interactive(env: Env) {
const HISTORY: &str = ".mal-history";
let home = get_home_path(&env).unwrap();
let history = home + "/" + HISTORY;
// Using "Editor" instead of the standard I/O because I hate myself but not this much
// TODO: remove unwrap and switch to a better error handling
let mut rl = DefaultEditor::new().unwrap();
if rl.load_history(&(home + "/" + HISTORY)).is_err() {
if rl.load_history(&history).is_err() {
eprintln!("; Failed to load history");
}
@ -96,7 +97,7 @@ pub fn interactive(env: Env) {
Ok(line) => {
// TODO: should handle this in a different way
rl.add_history_entry(&line).unwrap();
rl.save_history(HISTORY).unwrap();
rl.save_history(&history).unwrap();
parser.push(&line);

View File

@ -102,7 +102,7 @@ impl Reader {
if tk.len() > 2 && tk.ends_with('\"') {
Ok(Str(unescape_str(tk)))
} else {
Err(MalErr::recoverable(
Err(MalErr::unrecoverable(
"End of line reached without closing string",
))
}