You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I use append_history after adding an entry, it seems to add an extra blank line after the entry, is this expected behavior?
I was hoping to use this instead of save_history in order to save on performance (my understanding is that it appends to the file instead of writing out a whole new one).
Code ran:
use rustyline::error::ReadlineError;
use rustyline::Editor;
use std::fs::File;
use std::io::{BufRead, BufReader};
fn main() -> Result<(), ReadlineError> {
let mut rl = Editor::<()>::new();
let path: &str = "history.txt";
if rl.load_history(&path).is_err() {
println!("No previous history.");
}
loop {
match rl.readline("> ") {
Ok(line) if line == "clear" => {
let _ = File::create(&path);
rl.clear_history();
}
Ok(line) if line == "exit" => {
break;
}
Ok(line) if line == "history" => {
let f = File::open(&path)?;
for line in BufReader::new(f).lines().skip(1) {
println!("{}", line?);
}
}
Ok(line) => {
rl.add_history_entry(&line);
let _ = rl.append_history(&path);
println!("Line: {}", line);
}
Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
break;
}
Err(ReadlineError::Eof) => {
println!("CTRL-D");
break;
}
Err(err) => {
println!("Error: {:?}", err);
break;
}
}
}
let _ = rl.save_history(path)?;
Ok(())
}
File output after running a few lines, via bat history.txt:
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: history.txt
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ #V2
2 │ a
3 │
4 │ b
5 │
6 │ c
The text was updated successfully, but these errors were encountered:
If I use
append_history
after adding an entry, it seems to add an extra blank line after the entry, is this expected behavior?I was hoping to use this instead of
save_history
in order to save on performance (my understanding is that it appends to the file instead of writing out a whole new one).Code ran:
File output after running a few lines, via
bat history.txt
:The text was updated successfully, but these errors were encountered: