summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-10-20 21:29:56 +0800
committerGitHub <noreply@github.com>2024-10-20 21:29:56 +0800
commita165fd19e752e3a998dedfe640e9ec838c2737c6 (patch)
tree252676ba49cdb00bdb90e86f58510b58a112f2a7
parentac89b7ad6716a8af811089b130c2039627d47b48 (diff)
downloadaichat-a165fd19e752e3a998dedfe640e9ec838c2737c6.tar.gz
refactor: improve REPL (#940)
-rw-r--r--src/repl/completer.rs7
-rw-r--r--src/repl/mod.rs2
2 files changed, 6 insertions, 3 deletions
diff --git a/src/repl/completer.rs b/src/repl/completer.rs
index 0771001..12e871a 100644
--- a/src/repl/completer.rs
+++ b/src/repl/completer.rs
@@ -1,6 +1,6 @@
use super::{ReplCommand, REPL_COMMANDS};
-use crate::config::GlobalConfig;
+use crate::{config::GlobalConfig, utils::fuzzy_match};
use reedline::{Completer, Span, Suggestion};
use std::collections::HashMap;
@@ -42,7 +42,10 @@ impl Completer for ReplCompleter {
.map(|(v, _)| *v)
.collect::<Vec<&str>>()
.join(" ");
- cmd.name.starts_with(&line) && cmd.name != ".set"
+ if line == "." {
+ return true;
+ }
+ line.starts_with(&cmd.name[..2]) && fuzzy_match(cmd.name, &line)
})
.collect();
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index 735ad25..6b026b5 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -162,9 +162,9 @@ lazy_static::lazy_static! {
"Regenerate the last response",
AssertState::pass()
),
+ ReplCommand::new(".copy", "Copy the last response", AssertState::pass()),
ReplCommand::new(".set", "Adjust runtime configuration", AssertState::pass()),
ReplCommand::new(".delete", "Delete roles/sessions/RAGs/agents", AssertState::pass()),
- ReplCommand::new(".copy", "Copy the last response", AssertState::pass()),
ReplCommand::new(".exit", "Exit the REPL", AssertState::pass()),
];
static ref COMMAND_RE: Regex = Regex::new(r"^\s*(\.\S*)\s*").unwrap();