diff options
| -rw-r--r-- | config.example.yaml | 6 | ||||
| -rw-r--r-- | src/config/mod.rs | 30 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/repl/mod.rs | 4 |
4 files changed, 26 insertions, 16 deletions
diff --git a/config.example.yaml b/config.example.yaml index e423d37..5941353 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -9,7 +9,11 @@ wrap_code: false # Whether wrap code block ctrlc_exit: false # Whether to exit REPL when Ctrl+C is pressed auto_copy: false # Automatically copy the last output to the clipboard keybindings: emacs # REPL keybindings. (emacs, vi) -prelude: '' # Set a default role or session (role:<name>, session:<name>) +prelude: null # Set a default role or session (role:<name>, session:<name>) + +# Command that will be used to edit the current line buffer with ctrl+o +# if unset fallback to $EDITOR and $VISUAL +buffer_editor: null # Compress session if tokens exceed this value (valid when >=1000) compress_threshold: 1000 diff --git a/src/config/mod.rs b/src/config/mod.rs index 88235ac..963ad50 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -70,7 +70,9 @@ pub struct Config { /// REPL keybindings. (emacs, vi) pub keybindings: Keybindings, /// Set a default role or session (role:<name>, session:<name>) - pub prelude: String, + pub prelude: Option<String>, + /// Command that will be used to edit the current line buffer + pub buffer_editor: Option<String>, /// Compress session if tokens exceed this value (>=1000) pub compress_threshold: usize, /// The prompt for summarizing session messages @@ -115,7 +117,8 @@ impl Default for Config { ctrlc_exit: false, auto_copy: false, keybindings: Default::default(), - prelude: String::new(), + prelude: None, + buffer_editor: None, compress_threshold: 2000, summarize_prompt: "Summarize the discussion briefly in 200 words or less to use as a prompt for future context.".to_string(), summary_prompt: "This is a summary of the chat history as a recap: ".into(), @@ -171,8 +174,11 @@ impl Config { Ok(config) } - pub fn prelude(&mut self) -> Result<()> { - let prelude = self.prelude.clone(); + pub fn apply_prelude(&mut self) -> Result<()> { + let prelude = self.prelude.clone().unwrap_or_default(); + if prelude.is_empty() { + return Ok(()); + } let err_msg = || format!("Invalid prelude '{}", prelude); match prelude.split_once(':') { Some(("role", name)) => { @@ -185,14 +191,19 @@ impl Config { self.start_session(Some(name)).with_context(err_msg)?; } } - Some(_) => { + _ => { bail!("{}", err_msg()) } - None => {} } Ok(()) } + pub fn buffer_editor(&self) -> Option<String> { + self.buffer_editor + .clone() + .or_else(|| env::var("VISUAL").ok().or_else(|| env::var("EDITOR").ok())) + } + pub fn retrieve_role(&self, name: &str) -> Result<Role> { self.roles .iter() @@ -413,11 +424,6 @@ impl Config { .wrap .clone() .map_or_else(|| String::from("no"), |v| v.to_string()); - let prelude = if self.prelude.is_empty() { - String::from("-") - } else { - self.prelude.clone() - }; let items = vec