From bc44026ff8828f532e9eba138e2ba35f7c247271 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 28 Oct 2023 21:39:17 +0800 Subject: feat: enhance session/conversation (#162) * feat: enhance session/conversation * updates * updates * cut version v0.9.0-rc2 * add .session name completion --- src/repl/handler.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/repl/handler.rs') diff --git a/src/repl/handler.rs b/src/repl/handler.rs index 1952ebe..fd157dc 100644 --- a/src/repl/handler.rs +++ b/src/repl/handler.rs @@ -21,8 +21,8 @@ pub enum ReplCmd { Prompt(String), ClearRole, ViewInfo, - StartConversation, - EndConversatoin, + StartSession(Option), + EndSession, Copy, ReadFile(String), } @@ -30,7 +30,6 @@ pub enum ReplCmd { #[allow(clippy::module_name_repetitions)] pub struct ReplCmdHandler { config: SharedConfig, - reply: RefCell, abort: SharedAbortSignal, clipboard: std::result::Result, arboard::Error>, } @@ -38,11 +37,9 @@ pub struct ReplCmdHandler { impl ReplCmdHandler { #[allow(clippy::unnecessary_wraps)] pub fn init(config: SharedConfig, abort: SharedAbortSignal) -> Result { - let reply = RefCell::new(String::new()); let clipboard = Clipboard::new().map(RefCell::new); Ok(Self { config, - reply, abort, clipboard, }) @@ -52,7 +49,6 @@ impl ReplCmdHandler { match cmd { ReplCmd::Submit(input) => { if input.is_empty() { - self.reply.borrow_mut().clear(); return Ok(()); } self.config.read().maybe_print_send_tokens(&input); @@ -68,12 +64,10 @@ impl ReplCmdHandler { ); wg.wait(); let buffer = ret?; - self.config.read().save_message(&input, &buffer)?; + self.config.write().save_message(&input, &buffer)?; if self.config.read().auto_copy { let _ = self.copy(&buffer); } - self.config.write().save_conversation(&input, &buffer)?; - *self.reply.borrow_mut() = buffer; } ReplCmd::SetModel(name) => { self.config.write().set_model(&name)?; @@ -99,16 +93,23 @@ impl ReplCmdHandler { self.config.write().update(&input)?; print_now!("\n"); } - ReplCmd::StartConversation => { - self.config.write().start_conversation()?; + ReplCmd::StartSession(name) => { + self.config.write().start_session(&name)?; print_now!("\n"); } - ReplCmd::EndConversatoin => { - self.config.write().end_conversation(); + ReplCmd::EndSession => { + self.config.write().end_session()?; print_now!("\n"); } ReplCmd::Copy => { - self.copy(&self.reply.borrow()) + let reply = self + .config + .read() + .last_message + .as_ref() + .map(|v| v.1.clone()) + .unwrap_or_default(); + self.copy(&reply) .with_context(|| "Failed to copy the last output")?; print_now!("\n"); } -- cgit v1.2.3