From 497136dbe8008055b4f6c54a92ef3b02e41d1770 Mon Sep 17 00:00:00 2001 From: kaichaosun Date: Fri, 17 Apr 2026 13:52:30 +0800 Subject: [PATCH] chore: fix clippy and refactor --- bin/chat-cli/src/main.rs | 9 +++------ bin/chat-cli/src/ui.rs | 38 ++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/bin/chat-cli/src/main.rs b/bin/chat-cli/src/main.rs index ca9baf4..7634abd 100644 --- a/bin/chat-cli/src/main.rs +++ b/bin/chat-cli/src/main.rs @@ -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") } diff --git a/bin/chat-cli/src/ui.rs b/bin/chat-cli/src/ui.rs index 42c5435..ce280d1 100644 --- a/bin/chat-cli/src/ui.rs +++ b/bin/chat-cli/src/ui.rs @@ -205,30 +205,28 @@ pub fn handle_events(app: &mut ChatApp) -> io::Result { 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) => {