mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-05-13 05:29:34 +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 transport;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
/// Get the data directory (in project folder).
|
/// Get the data directory (in project folder).
|
||||||
fn get_data_dir() -> PathBuf {
|
fn get_data_dir() -> PathBuf {
|
||||||
// Use the directory where the binary is or current working directory
|
env::current_dir()
|
||||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
.unwrap_or_else(|_| PathBuf::from("."))
|
||||||
PathBuf::from(manifest_dir)
|
|
||||||
.parent()
|
|
||||||
.unwrap_or(&PathBuf::from("."))
|
|
||||||
.join("tmp/chat-cli-data")
|
.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) => {
|
KeyCode::Char('c') if key.modifiers.contains(event::KeyModifiers::CONTROL) => {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter if !app.input.is_empty() => {
|
||||||
if !app.input.is_empty() {
|
let input = std::mem::take(&mut app.input);
|
||||||
let input = std::mem::take(&mut app.input);
|
|
||||||
|
|
||||||
if input.starts_with('/') {
|
if input.starts_with('/') {
|
||||||
match app.handle_command(&input) {
|
match app.handle_command(&input) {
|
||||||
Ok(Some(response)) => {
|
Ok(Some(response)) => {
|
||||||
app.status = response;
|
app.status = response;
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
// Quit signal
|
|
||||||
return Ok(false);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
app.status = format!("Error: {}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if app.current_session().is_some() {
|
Ok(None) => {
|
||||||
if let Err(e) = app.send_message(&input) {
|
// Quit signal
|
||||||
app.status = format!("Send error: {}", e);
|
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) => {
|
KeyCode::Char(c) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user