summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/mod.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 407d041..fd23eb1 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -35,7 +35,7 @@ use std::{
io::Write,
path::{Path, PathBuf},
process,
- sync::Arc,
+ sync::{Arc, OnceLock},
};
use syntect::highlighting::ThemeSet;
@@ -88,6 +88,8 @@ __INPUT__
const LEFT_PROMPT: &str = "{color.green}{?session {?agent {agent}>}{session}{?role /}}{!session {?agent {agent}>}}{role}{?rag @{rag}}{color.cyan}{?session )}{!session >}{color.reset} ";
const RIGHT_PROMPT: &str = "{color.purple}{?session {?consume_tokens {consume_tokens}({consume_percent}%)}{!consume_tokens {consume_tokens}}}{color.reset}";
+static EDITOR: OnceLock<Option<String>> = OnceLock::new();
+
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
pub struct Config {
@@ -1640,10 +1642,20 @@ impl Config {
}
pub fn editor(&self) -> Result<String> {
- self.editor
- .clone()
- .or_else(|| env::var("VISUAL").ok().or_else(|| env::var("EDITOR").ok()))
- .ok_or_else(|| anyhow!("No editor, please configure `editor` or set $EDITOR/$VISUAL environment variable."))
+ EDITOR.get_or_init(move || {
+ let editor = self.editor.clone()
+ .or_else(|| env::var("VISUAL").ok().or_else(|| env::var("EDITOR").ok()))
+ .unwrap_or_else(|| {
+ if cfg!(windows) {
+ "notepad".to_string()
+ } else {
+ "nano".to_string()
+ }
+ });
+ which::which(&editor).ok().map(|_| editor)
+ })
+ .clone()
+ .ok_or_else(|| anyhow!("Editor not found. Please add the `editor` configuration or set the $EDITOR or $VISUAL environment variable."))
}
pub fn repl_complete(