From c7fcdb174440817706b818154a6bbcaf58948caa Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 7 Mar 2023 19:04:54 +0800 Subject: refactor: adjust repl (#30) - abandon .copy - rename .multiple => .editor - if command successed, do not output `Done` - if command failed, output `Error: ` --- src/repl/mod.rs | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'src/repl/mod.rs') diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 30e1c5e..e08b798 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -5,7 +5,7 @@ mod init; use crate::client::ChatGptClient; use crate::config::SharedConfig; use crate::term; -use crate::utils::{copy, dump}; +use crate::utils::dump; use anyhow::{Context, Result}; use reedline::{DefaultPrompt, Reedline, Signal}; @@ -14,17 +14,15 @@ use std::sync::Arc; pub use self::abort::*; pub use self::handler::*; -pub const REPL_COMMANDS: [(&str, &str, bool); 12] = [ +pub const REPL_COMMANDS: [(&str, &str, bool); 10] = [ (".info", "Print the information", false), (".set", "Modify the configuration temporarily", false), + (".prompt", "Add a GPT prompt", true), (".role", "Select a role", false), (".clear role", "Clear the currently selected role", false), - (".prompt", "Add prompt, aka create a temporary role", true), (".history", "Print the history", false), (".clear history", "Clear the history", false), - (".clear screen", "Clear the screen", false), - (".multiline", "Enter multiline editor mode", true), - (".copy", "Copy last reply message", false), + (".editor", "Enter editor mode for multiline input", true), (".help", "Print this help message", false), (".exit", "Exit the REPL", false), ]; @@ -122,10 +120,10 @@ impl Repl { ".info" => { handler.handle(ReplCmd::Info)?; } - ".multiline" => { + ".editor" => { let mut text = args.unwrap_or_default().to_string(); if text.is_empty() { - dump("Usage: .multiline { }", 2); + dump("Usage: .editor { }", 2); } else { if text.starts_with('{') && text.ends_with('}') { text = text[1..text.len() - 1].to_string() @@ -133,22 +131,13 @@ impl Repl { handler.handle(ReplCmd::Submit(text))?; } } - ".copy" => { - let reply = handler.get_reply(); - if reply.is_empty() { - dump("No reply messages that can be copied", 1) - } else { - copy(&reply)?; - dump("Copied", 1); - } - } ".set" => { handler.handle(ReplCmd::UpdateConfig(args.unwrap_or_default().to_string()))? } ".prompt" => { let mut text = args.unwrap_or_default().to_string(); if text.is_empty() { - dump("Usage: .prompt { }.", 2); + dump("Usage: .prompt { }.", 2); } else { if text.starts_with('{') && text.ends_with('}') { text = text[1..text.len() - 1].to_string() @@ -167,7 +156,10 @@ impl Repl { } fn dump_unknown_command() { - dump("Unknown command. Type \".help\" for more information.", 2); + dump( + "Error: Unknown command. Type \".help\" for more information.", + 2, + ); } fn dump_repl_help() { -- cgit v1.2.3