diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/mod.rs | 29 | ||||
| -rw-r--r-- | src/main.rs | 1 | ||||
| -rw-r--r-- | src/render/repl.rs | 2 | ||||
| -rw-r--r-- | src/repl/mod.rs | 2 |
4 files changed, 30 insertions, 4 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index e6fef5f..22c58bb 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -60,9 +60,11 @@ pub struct Config { pub wrap_code: bool, /// Automatically copy the last output to the clipboard pub auto_copy: bool, - /// REPL keybindings. values: emacs, vi + /// REPL keybindings. (emacs, vi) pub keybindings: Keybindings, - /// Setup AIs + /// Set a default role or session (role:<name>, session:<name>) + pub prelude: String, + /// Setup clients pub clients: Vec<ClientConfig>, /// Predefined roles #[serde(skip)] @@ -94,6 +96,7 @@ impl Default for Config { wrap_code: false, auto_copy: false, keybindings: Default::default(), + prelude: String::new(), clients: vec![ClientConfig::default()], roles: vec![], role: None, @@ -145,6 +148,28 @@ impl Config { Ok(config) } + pub fn onstart(&mut self) -> Result<()> { + let prelude = self.prelude.clone(); + let err_msg = || format!("Invalid prelude '{}", prelude); + match prelude.split_once(':') { + Some(("role", name)) => { + if self.role.is_none() && self.session.is_none() { + self.set_role(name).with_context(err_msg)?; + } + } + Some(("session", name)) => { + if self.session.is_none() { + self.start_session(Some(name)).with_context(err_msg)?; + } + } + Some(_) => { + bail!("{}", err_msg()) + } + None => {} + } + Ok(()) + } + pub fn retrieve_role(&self, name: &str) -> Result<Role> { self.roles .iter() diff --git a/src/main.rs b/src/main.rs index a40745f..368779e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,6 +77,7 @@ fn main() -> Result<()> { println!("{}", info); exit(0); } + config.write().onstart()?; let no_stream = cli.no_stream; let client = init_client(&config)?; if stdin().is_terminal() { diff --git a/src/render/repl.rs b/src/render/repl.rs index 34212c3..ca11e17 100644 --- a/src/render/repl.rs +++ b/src/render/repl.rs @@ -83,7 +83,7 @@ fn repl_render_stream_inner( queue!(writer, style::Print(&buffer),)?; // No guarantee the buffer width of the buffer will not exceed the number of columns. - // So we calcuate the number of rows needed, rather than setting it directly to 1. + // So we calculate the number of rows needed, rather than setting it directly to 1. buffer_rows = need_rows(&buffer, columns); } else { buffer = format!("{buffer}{text}"); diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 3962229..a4f397c 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -32,7 +32,7 @@ const REPL_COMMANDS: [(&str, &str); 14] = [ (".info", "Print system info"), (".edit", "Multi-line editing (CTRL+S to finish)"), (".model", "Switch LLM model"), - (".role", "Use role"), + (".role", "Use a role"), (".info role", "Show role info"), (".exit role", "Leave current role"), (".session", "Start a context-aware chat session"), |
