Commit 48478bd1 authored by stratact's avatar stratact

Apply mmstick's suggestion

parent a5eda99e
Pipeline #1569 passed with stage
in 1 minute and 45 seconds
......@@ -2,7 +2,7 @@ use super::*;
use std::{
collections::{vec_deque, VecDeque},
io::{BufRead, BufReader},
io::{BufRead, BufReader, BufWriter},
fs::File,
io::{self, Seek, SeekFrom, Write},
iter::IntoIterator,
......@@ -143,18 +143,15 @@ impl History {
}
}
let mut file = File::create(&file_name)
let mut file = BufWriter::new(File::create(&file_name)
// It's safe to unwrap, because the file has be loaded by this time
.unwrap();
.unwrap());
let mut file_buffer = String::new();
// Write the command to the history file.
for buffer in &self.buffers {
file_buffer.push_str(&String::from(buffer.clone()));
file_buffer.push_str("\n");
// Write the commands to the history file.
for command in self.buffers.iter().cloned() {
let _ = file.write_all(&String::from(command).as_bytes());
let _ = file.write_all(b"\n");
}
let _ = file.write_all(file_buffer.as_bytes());
let _ = file.flush();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment