summaryrefslogtreecommitdiff
path: root/cli/tools/repl/mod.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-11-25 02:56:47 +0100
committerGitHub <noreply@github.com>2022-11-25 02:56:47 +0100
commit433f38084bba9f18bdb5de22422cbbd5b0c01ff7 (patch)
tree9b8312967987bd9f31d29e70b30764223b1bd3ce /cli/tools/repl/mod.rs
parente6a9588b4375f7ff3f445d13e4cd4b3c334d451c (diff)
fix(repl): more reliable history handling (#16797)
This commit changes history handling of the REPL. There were some situations were history wasn't properly saved and flushed to a file, making history very spotty. This commit changes it to save every line into the history file and flush it to disk before being evaluated. Thanks to this all lines, including "close()" will be stored in the history file. If for any reason we're not able to save history file, a single warning will be printed to the REPL and it will continue to work, even if subsequent tries will fail to save to disk.
Diffstat (limited to 'cli/tools/repl/mod.rs')
-rw-r--r--cli/tools/repl/mod.rs7
1 files changed, 2 insertions, 5 deletions
diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs
index c8efd3d95..e37591583 100644
--- a/cli/tools/repl/mod.rs
+++ b/cli/tools/repl/mod.rs
@@ -89,7 +89,7 @@ pub async fn run(
};
let history_file_path = ps.dir.root.join("deno_history.txt");
- let editor = ReplEditor::new(helper, history_file_path);
+ let editor = ReplEditor::new(helper, history_file_path)?;
if let Some(eval_files) = maybe_eval_files {
for eval_file in eval_files {
@@ -131,6 +131,7 @@ pub async fn run(
match line {
Ok(line) => {
should_exit_on_interrupt = false;
+ editor.update_history(line.clone());
let output = repl_session.evaluate_line_and_get_output(&line).await?;
// We check for close and break here instead of making it a loop condition to get
@@ -140,8 +141,6 @@ pub async fn run(
}
println!("{}", output);
-
- editor.add_history_entry(line);
}
Err(ReadlineError::Interrupted) => {
if should_exit_on_interrupt {
@@ -161,7 +160,5 @@ pub async fn run(
}
}
- editor.save_history()?;
-
Ok(repl_session.worker.get_exit_code())
}