From 23e9fb5bbf96cd4a93f4150659a99b4055623b9f Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 30 Oct 2023 14:17:15 +0800 Subject: feat: deprecate .clear command (#180) --- src/repl/mod.rs | 66 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 28 deletions(-) (limited to 'src/repl/mod.rs') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 7a665ea..e5691dc 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -19,17 +19,17 @@ use reedline::Signal; use std::rc::Rc; pub const REPL_COMMANDS: [(&str, &str); 12] = [ + (".help", "Print this help message"), (".info", "Print system-wide information"), - (".set", "Modify the configuration temporarily"), - (".model", "Choose a model"), - (".role", "Select a role"), - (".clear role", "Clear the currently selected role"), - (".session", "Start a session"), - (".clear session", "End current session"), - (".copy", "Copy the last output to the clipboard"), - (".read", "Read the contents of a file and submit"), (".edit", "Multi-line editing (CTRL+S to finish)"), - (".help", "Print this help message"), + (".model", "Switch LLM model"), + (".role", "Use role"), + (".exit role", "Leave current role"), + (".session", "Start a context-aware chat session"), + (".exit session", "End the current session"), + (".set", "Modify the configuration parameters"), + (".copy", "Copy the last reply to the clipboard"), + (".read", "Import from file and submit"), (".exit", "Exit the REPL"), ]; @@ -85,24 +85,24 @@ impl Repl { _ => {} } } - handler.handle(ReplCmd::EndSession)?; + handler.handle(ReplCmd::ExitSession)?; Ok(()) } fn handle_line(&mut self, handler: &Rc, line: &str) -> Result { match parse_command(line) { Some((cmd, args)) => match cmd { - ".exit" => { - return Ok(true); - } ".help" => { dump_repl_help(); } - ".clear" => match args { - Some("role") => handler.handle(ReplCmd::ClearRole)?, - Some("session") => handler.handle(ReplCmd::EndSession)?, - _ => dump_unknown_command(), - }, + ".info" => { + handler.handle(ReplCmd::ViewInfo)?; + } + ".edit" => { + if let Some(text) = args { + handler.handle(ReplCmd::Submit(text.to_string()))?; + } + } ".model" => match args { Some(name) => handler.handle(ReplCmd::SetModel(name.to_string()))?, None => print_now!("Usage: .model \n\n"), @@ -111,16 +111,13 @@ impl Repl { Some(name) => handler.handle(ReplCmd::SetRole(name.to_string()))?, None => print_now!("Usage: .role \n\n"), }, - ".info" => { - handler.handle(ReplCmd::ViewInfo)?; + ".session" => { + handler.handle(ReplCmd::StartSession(args.map(|v| v.to_string())))?; } ".set" => { - handler.handle(ReplCmd::UpdateConfig(args.unwrap_or_default().to_string()))?; + handler.handle(ReplCmd::Set(args.unwrap_or_default().to_string()))?; self.prompt.sync_config(); } - ".session" => { - handler.handle(ReplCmd::StartSession(args.map(|v| v.to_string())))?; - } ".copy" => { handler.handle(ReplCmd::Copy)?; } @@ -128,11 +125,24 @@ impl Repl { Some(file) => handler.handle(ReplCmd::ReadFile(file.to_string()))?, None => print_now!("Usage: .read \n\n"), }, - ".edit" => { - if let Some(text) = args { - handler.handle(ReplCmd::Submit(text.to_string()))?; + ".exit" => match args { + Some("role") => handler.handle(ReplCmd::ExitRole)?, + Some("session") => handler.handle(ReplCmd::ExitSession)?, + Some(_) => dump_unknown_command(), + None => { + return Ok(true); } - } + }, + // deprecated + ".clear" => match args { + Some("role") => { + print_now!("Deprecated. Use '.exit role' instead.\n\n"); + } + Some("session") => { + print_now!("Deprecated. Use '.exit session' instead.\n\n"); + } + _ => dump_unknown_command(), + }, _ => dump_unknown_command(), }, None => { -- cgit v1.2.3