diff options
| author | sigoden <sigoden@gmail.com> | 2024-02-24 19:13:48 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-24 19:13:48 +0800 |
| commit | 21d1be5bedb13d08462e9800a1c3cbf93dd585bc (patch) | |
| tree | f21874bd7fefa25fccf443df1249cdf3c74e0763 /src/config | |
| parent | 16b7ac071f3feed52939c2244ede2f0abe5230a2 (diff) | |
| download | aichat-21d1be5bedb13d08462e9800a1c3cbf93dd585bc.tar.gz | |
refactor: improve prompt error handling (#319)
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/mod.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index d38cbf3..f8d97c2 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -11,7 +11,7 @@ use crate::client::{ Model, OpenAIClient, SendData, }; use crate::render::{MarkdownRender, RenderOptions}; -use crate::utils::{get_env_name, light_theme_from_colorfgbg, now, prompt_op_err, render_prompt}; +use crate::utils::{get_env_name, light_theme_from_colorfgbg, now, render_prompt}; use anyhow::{anyhow, bail, Context, Result}; use inquire::{Confirm, Select, Text}; @@ -577,8 +577,7 @@ impl Config { "Start a session that incorporates the last question and answer?", ) .with_default(false) - .prompt() - .map_err(prompt_op_err)?; + .prompt()?; if ans { session.add_message(input, output)?; } @@ -593,19 +592,13 @@ impl Config { self.last_message = None; self.temperature = self.default_temperature; if session.should_save() { - let ans = Confirm::new("Save session?") - .with_default(false) - .prompt() - .map_err(prompt_op_err)?; + let ans = Confirm::new("Save session?").with_default(false).prompt()?; if !ans { return Ok(()); } let mut name = session.name().to_string(); if session.is_temp() { - name = Text::new("Session name:") - .with_default(&name) - .prompt() - .map_err(prompt_op_err)?; + name = Text::new("Session name:").with_default(&name).prompt()?; } let session_path = Self::session_file(&name)?; let sessions_dir = session_path.parent().ok_or_else(|| { @@ -917,15 +910,12 @@ pub enum State { fn create_config_file(config_path: &Path) -> Result<()> { let ans = Confirm::new("No config file, create a new one?") .with_default(true) - .prompt() - .map_err(prompt_op_err)?; + .prompt()?; if !ans { exit(0); } - let client = Select::new("Platform:", list_client_types()) - .prompt() - .map_err(prompt_op_err)?; + let client = Select::new("Platform:", list_client_types()).prompt()?; let mut config = serde_json::json!({}); config["model"] = client.into(); |
