diff options
| author | sigoden <sigoden@gmail.com> | 2024-08-01 15:01:34 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-01 15:01:34 +0800 |
| commit | 4a04465a3fd7703dbf063c41cc9b758ee4bb430f (patch) | |
| tree | 8d8882668f67f6b4f0a59cd6218fb425f345a7a4 /src/config/mod.rs | |
| parent | 6aa541912babb6e41d25d5daf8efbe333bc5e6b4 (diff) | |
| download | aichat-4a04465a3fd7703dbf063c41cc9b758ee4bb430f.tar.gz | |
feat: rename `config.buffer_editor` to `config.editor` (#773)
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 7cd5a17..1c9ae9d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -91,7 +91,7 @@ pub struct Config { pub stream: bool, pub save: bool, pub keybindings: String, - pub buffer_editor: Option<String>, + pub editor: Option<String>, pub wrap: Option<String>, pub wrap_code: bool, @@ -159,7 +159,7 @@ impl Default for Config { stream: true, save: false, keybindings: "emacs".into(), - buffer_editor: None, + editor: None, wrap: None, wrap_code: false, @@ -841,10 +841,7 @@ impl Config { Some(session) => session.name().to_string(), None => bail!("No session"), }; - let editor = match self.buffer_editor() { - Some(editor) => editor, - None => bail!("No editor, please set $EDITOR/$VISUAL."), - }; + let editor = self.editor()?; let session_path = self.session_file(&name)?; self.save_session(Some(&name))?; edit_file(&editor, &session_path).with_context(|| { @@ -1191,10 +1188,11 @@ impl Config { } } - pub fn buffer_editor(&self) -> Option<String> { - self.buffer_editor + 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.")) } pub fn repl_complete( @@ -1596,8 +1594,8 @@ impl Config { self.keybindings = v; } } - if let Some(v) = read_env_value::<String>("buffer_editor") { - self.buffer_editor = v; + if let Some(v) = read_env_value::<String>("editor") { + self.editor = v; } if let Some(v) = read_env_value::<String>("wrap") { self.wrap = v; |
