From 189f2271bcc6f841264cb960e35e78c870663645 Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 17 Jun 2024 10:59:59 +0800 Subject: feat: add `.edit session` repl command (#606) --- src/repl/mod.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/repl/mod.rs') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 48d8224..5b37d36 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -33,7 +33,7 @@ lazy_static! { const MENU_NAME: &str = "completion_menu"; lazy_static! { - static ref REPL_COMMANDS: [ReplCommand; 23] = [ + static ref REPL_COMMANDS: [ReplCommand; 24] = [ ReplCommand::new(".help", "Show this help message", AssertState::pass()), ReplCommand::new(".info", "View system info", AssertState::pass()), ReplCommand::new(".model", "Change the current LLM", AssertState::pass()), @@ -72,6 +72,11 @@ lazy_static! { "Save the chat to file", AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION) ), + ReplCommand::new( + ".edit session", + "Edit the current session", + AssertState::True(StateFlags::SESSION_EMPTY | StateFlags::SESSION) + ), ReplCommand::new( ".clear messages", "Erase messages in the current session", @@ -279,8 +284,8 @@ Tips: use to autocomplete conversation starter text. }, ".save" => { match args.map(|v| match v.split_once(' ') { - Some((subcmd, args)) => (subcmd, args.trim()), - None => (v, ""), + Some((subcmd, args)) => (subcmd, Some(args.trim())), + None => (v, None), }) { Some(("session", name)) => { self.config.write().save_session(name)?; @@ -290,6 +295,19 @@ Tips: use to autocomplete conversation starter text. } } } + ".edit" => { + match args.map(|v| match v.split_once(' ') { + Some((subcmd, args)) => (subcmd, Some(args.trim())), + None => (v, None), + }) { + Some(("session", _)) => { + self.config.write().edit_session()?; + } + _ => { + println!(r#"Usage: .edit session"#) + } + } + } ".set" => match args { Some(args) => { self.config.write().update(args)?; -- cgit v1.2.3