refactor: 'temp' can not be used as name of saved session (#591)

pull/592/head
sigoden 2 weeks ago committed by GitHub
parent b24cb66309
commit fe3a22255d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -686,7 +686,7 @@ impl Config {
}
let mut session;
match session_name {
None => {
None | Some(TEMP_SESSION_NAME) => {
let session_file = self.session_file(TEMP_SESSION_NAME)?;
if session_file.exists() {
remove_file(session_file).with_context(|| {

@ -5,7 +5,7 @@ use crate::client::{Message, MessageContent, MessageRole};
use crate::render::MarkdownRender;
use anyhow::{bail, Context, Result};
use inquire::{required, Confirm, Text};
use inquire::{validator::Validation, Confirm, Text};
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::collections::HashMap;
@ -306,7 +306,15 @@ impl Session {
}
if self.is_temp() {
self.name = Text::new("Session name:")
.with_validator(required!("This field is required"))
.with_validator(|input: &str| {
if input == TEMP_SESSION_NAME {
Ok(Validation::Invalid(format!("'{TEMP_SESSION_NAME}' is a reserved word and cannot be used as a session name").into()))
} else if input.trim().is_empty() {
Ok(Validation::Invalid("This field is required".into()))
} else {
Ok(Validation::Valid)
}
})
.prompt()?;
}
}

Loading…
Cancel
Save