Handle EOF and interruptions more gracefully and correct.

This commit is contained in:
Oleksandr Kozachuk
2022-12-14 16:15:25 +01:00
parent 843b843b5e
commit 0c187b7b5b
+2
View File
@@ -1,5 +1,6 @@
use home::home_dir;
use rpassword::prompt_password;
use rustyline::error::ReadlineError;
use rustyline::Editor;
use regex::Regex;
use std::{cell::RefCell, rc::Rc};
@@ -56,6 +57,7 @@ impl LKRead {
}
self.cmd = match self.rl.readline(&*self.prompt) {
Ok(str) => str,
Err(ReadlineError::Eof | ReadlineError::Interrupted) => "quit".to_string(),
Err(err) => return LKEval::new(Command::Error(LKErr::ReadError(err.to_string())), self.state.clone(), self.read_password),
};
self.rl.add_history_entry(self.cmd.as_str());