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 | |
| parent | 6aa541912babb6e41d25d5daf8efbe333bc5e6b4 (diff) | |
| download | aichat-4a04465a3fd7703dbf063c41cc9b758ee4bb430f.tar.gz | |
feat: rename `config.buffer_editor` to `config.editor` (#773)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/mod.rs | 18 | ||||
| -rw-r--r-- | src/repl/mod.rs | 2 |
2 files changed, 9 insertions, 11 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; diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 18d00f9..490cc89 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -435,7 +435,7 @@ Type ".help" for additional help. .with_validator(Box::new(ReplValidator)) .with_ansi_colors(true); - if let Some(cmd) = config.read().buffer_editor() { + if let Ok(cmd) = config.read().editor() { let temp_file = temp_file("-repl-", ".txt"); let command = process::Command::new(cmd); editor = editor.with_buffer_editor(command, temp_file); |
