chore: fix clippy and refactor

This commit is contained in:
kaichaosun 2026-04-17 13:52:30 +08:00
parent d48d24a471
commit 497136dbe8
No known key found for this signature in database
GPG Key ID: 223E0F992F4F03BF
2 changed files with 21 additions and 26 deletions

View File

@ -28,17 +28,14 @@ mod app;
mod transport;
mod ui;
use std::path::PathBuf;
use std::{env, path::PathBuf};
use anyhow::{Context, Result};
/// Get the data directory (in project folder).
fn get_data_dir() -> PathBuf {
// Use the directory where the binary is or current working directory
let manifest_dir = env!("CARGO_MANIFEST_DIR");
PathBuf::from(manifest_dir)
.parent()
.unwrap_or(&PathBuf::from("."))
env::current_dir()
.unwrap_or_else(|_| PathBuf::from("."))
.join("tmp/chat-cli-data")
}

View File

@ -205,30 +205,28 @@ pub fn handle_events(app: &mut ChatApp) -> io::Result<bool> {
KeyCode::Char('c') if key.modifiers.contains(event::KeyModifiers::CONTROL) => {
return Ok(false);
}
KeyCode::Enter => {
if !app.input.is_empty() {
let input = std::mem::take(&mut app.input);
KeyCode::Enter if !app.input.is_empty() => {
let input = std::mem::take(&mut app.input);
if input.starts_with('/') {
match app.handle_command(&input) {
Ok(Some(response)) => {
app.status = response;
}
Ok(None) => {
// Quit signal
return Ok(false);
}
Err(e) => {
app.status = format!("Error: {}", e);
}
if input.starts_with('/') {
match app.handle_command(&input) {
Ok(Some(response)) => {
app.status = response;
}
} else if app.current_session().is_some() {
if let Err(e) = app.send_message(&input) {
app.status = format!("Send error: {}", e);
Ok(None) => {
// Quit signal
return Ok(false);
}
Err(e) => {
app.status = format!("Error: {}", e);
}
} else {
app.status = "No active chat. Use /connect first.".to_string();
}
} else if app.current_session().is_some() {
if let Err(e) = app.send_message(&input) {
app.status = format!("Send error: {}", e);
}
} else {
app.status = "No active chat. Use /connect first.".to_string();
}
}
KeyCode::Char(c) => {