summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-08-01 15:01:34 +0800
committerGitHub <noreply@github.com>2024-08-01 15:01:34 +0800
commit4a04465a3fd7703dbf063c41cc9b758ee4bb430f (patch)
tree8d8882668f67f6b4f0a59cd6218fb425f345a7a4
parent6aa541912babb6e41d25d5daf8efbe333bc5e6b4 (diff)
downloadaichat-4a04465a3fd7703dbf063c41cc9b758ee4bb430f.tar.gz
feat: rename `config.buffer_editor` to `config.editor` (#773)
-rw-r--r--config.example.yaml4
-rw-r--r--src/config/mod.rs18
-rw-r--r--src/repl/mod.rs2
3 files changed, 11 insertions, 13 deletions
diff --git a/config.example.yaml b/config.example.yaml
index cc0f7d8..6f3e006 100644
--- a/config.example.yaml
+++ b/config.example.yaml
@@ -4,10 +4,10 @@ temperature: null # Set default temperature parameter
top_p: null # Set default top-p parameter, range (0, 1)
# ---- behavior ----
-stream: true # Use stream style by default
+stream: true # Controls whether to use the stream-style API.
save: true # Indicates whether to persist the message
keybindings: emacs # Choose keybinding style (emacs, vi)
-buffer_editor: null # Command used to edit the current input with ctrl+o, env: EDITOR
+editor: null # Command used to edit buffer, session.yaml and config.yaml. env: EDITOR
wrap: no # Controls text wrapping (no, auto, <max-width>)
wrap_code: false # Enables or disables wrapping of code blocks
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);