diff options
| author | sigoden <sigoden@gmail.com> | 2023-03-08 11:27:51 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 11:27:51 +0800 |
| commit | b7cb6f89f137e20f1d6dbb1f66e40f319c978a45 (patch) | |
| tree | 85ebf416d8ce8b2bbb808237578dca5b5be712e2 /src/repl/handler.rs | |
| parent | b05fce7bca0e0e69851dc609eb527956304defcf (diff) | |
| download | aichat-b7cb6f89f137e20f1d6dbb1f66e40f319c978a45.tar.gz | |
fix: repl set save true not work if not rerun(#34)
Diffstat (limited to 'src/repl/handler.rs')
| -rw-r--r-- | src/repl/handler.rs | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs index 384fce0..e971ff8 100644 --- a/src/repl/handler.rs +++ b/src/repl/handler.rs @@ -7,7 +7,6 @@ use anyhow::Result; use crossbeam::channel::Sender; use crossbeam::sync::WaitGroup; use std::cell::RefCell; -use std::fs::File; use super::abort::SharedAbortSignal; @@ -23,30 +22,21 @@ pub enum ReplCmd { pub struct ReplCmdHandler { client: ChatGptClient, config: SharedConfig, - state: RefCell<ReplCmdHandlerState>, + reply: RefCell<String>, abort: SharedAbortSignal, } -pub struct ReplCmdHandlerState { - reply: String, - save_file: Option<File>, -} - impl ReplCmdHandler { pub fn init( client: ChatGptClient, config: SharedConfig, abort: SharedAbortSignal, ) -> Result<Self> { - let save_file = config.as_ref().borrow().open_message_file()?; - let state = RefCell::new(ReplCmdHandlerState { - save_file, - reply: String::new(), - }); + let reply = RefCell::new(String::new()); Ok(Self { client, config, - state, + reply, abort, }) } @@ -55,7 +45,7 @@ impl ReplCmdHandler { match cmd { ReplCmd::Submit(input) => { if input.is_empty() { - self.state.borrow_mut().reply.clear(); + self.reply.borrow_mut().clear(); return Ok(()); } let highlight = self.config.borrow().highlight; @@ -72,12 +62,8 @@ impl ReplCmdHandler { ); wg.wait(); let buffer = ret?; - self.config.borrow().save_message( - self.state.borrow_mut().save_file.as_mut(), - &input, - &buffer, - )?; - self.state.borrow_mut().reply = buffer; + self.config.borrow().save_message(&input, &buffer)?; + *self.reply.borrow_mut() = buffer; } ReplCmd::SetRole(name) => { let output = self.config.borrow_mut().change_role(&name); |
