From a066b0ad3ef44dfb3ab970ed9180c3b1c3d09df2 Mon Sep 17 00:00:00 2001 From: Weihao Zhu <134527871+zhuweihao12138@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhistory=5Fcommands=E6=B2=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=88=B0txt=E4=B8=AD=20(#39)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修改issues#38 bug: history_command没记录到txt中 * cargo fmt规范格式 --- src/shell/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index b41f5af..b0ebe60 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -101,12 +101,12 @@ impl Shell { { self.history_commands .push(Rc::new(RefCell::new(command_bytes.clone()))); + self.write_commands(); }; if !command_bytes.iter().all(|&byte| byte == b' ') { self.exec_commands_in_line(&command_bytes); } } - self.write_commands(); } fn exec_commands_in_line(&mut self, command_bytes: &Vec) { @@ -136,7 +136,8 @@ impl Shell { fn write_commands(&self) { let mut file = OpenOptions::new() - .append(false) + .write(true) + .truncate(true) .open("history_commands.txt") .unwrap(); for command_line in &self.history_commands {