mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-05-12 04:59:27 +00:00
chore: fix clippy and refactor
This commit is contained in:
parent
d48d24a471
commit
497136dbe8
@ -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")
|
||||
}
|
||||
|
||||
|
||||
@ -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) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user