diff --git a/Cargo.toml b/Cargo.toml index e08960f..ba63234 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,4 @@ url = "2.5.4" flume = "0.11.1" error-stack = "0.5.0" thiserror = "2.0.11" -chrono = { version = "0.4.39", features = ["serde"] } \ No newline at end of file +chrono = { version = "0.4.39", features = ["serde"] } diff --git a/bankcli/Cargo.toml b/bankcli/Cargo.toml index 23fb351..c104486 100644 --- a/bankcli/Cargo.toml +++ b/bankcli/Cargo.toml @@ -15,7 +15,6 @@ tracing.workspace = true tracing-subscriber.workspace = true clap.workspace = true url.workspace = true -lalrpop-util = "0.22.1" error-stack.workspace = true flume.workspace = true chrono.workspace = true diff --git a/bankcli/src/main.rs b/bankcli/src/main.rs index b6ff991..02c5c08 100644 --- a/bankcli/src/main.rs +++ b/bankcli/src/main.rs @@ -6,7 +6,7 @@ use error_stack::{report, Report}; use flume::Receiver; use std::io::stdin; use std::ops::Add; -use std::time::Duration; +use std::time::{Duration, SystemTime}; use std::thread; use tokio::select; use tracing::metadata::LevelFilter; @@ -20,6 +20,8 @@ struct Args { url: Option, #[arg(short, long)] debug: bool, + #[arg(short, long)] + benchmark: bool, } #[tokio::main] @@ -46,8 +48,10 @@ async fn main() { EnvFilter::builder() .with_default_directive(if args.debug { LevelFilter::DEBUG.into() - } else { + } else if !args.benchmark { LevelFilter::INFO.into() + } else { + LevelFilter::WARN.into() }) .from_env_lossy(), ) @@ -55,7 +59,7 @@ async fn main() { let config = load_config(); let url: Url; - if let Some(arg) = args.url { + if let Some(arg) = args.url.clone() { url = arg; } else { if !config.server.last_server.is_empty() && config.general.use_last_server { @@ -103,11 +107,20 @@ async fn main() { let lines = read_lines(); let messages = client.client.receiver_msg().clone(); let actions = client.client.receiver_act().clone(); + + if args.benchmark { + loop { + let time = SystemTime::now(); + handle_line(&mut client, &lines, "pm".into(), &args).await; + warn!("Getting PMs took {}ms", time.elapsed().unwrap().as_millis()); + } + } + for _ in actions.try_iter() {} loop { select! { Ok(line) = lines.recv_async() => { - if handle_line(&mut client, &lines, line).await { + if handle_line(&mut client, &lines, line, &args).await { break; } }, @@ -232,7 +245,7 @@ fn print_error(error: &Report) { error!("{}", error.as_error().to_string()); } -async fn handle_line(client: &mut Client, rx: &Receiver, line: String) -> bool { +async fn handle_line(client: &mut Client, rx: &Receiver, line: String, args: &Args) -> bool { let mut split = line.split(' '); let command: &str = split.next().unwrap(); @@ -523,7 +536,7 @@ async fn handle_line(client: &mut Client, rx: &Receiver, line: String) - } info!("*: Message not saved in the history"); info!("--- {} New Private Message{} ---", size, if size == 1 { "" } else { "s" }); - if ask_confirmation(rx, "Do you want to mark all messages as read?").await { + if !args.benchmark && ask_confirmation(rx, "Do you want to mark all messages as read?").await { handle_error(&client.move_all_new_pms().await); } } else { @@ -558,7 +571,7 @@ async fn handle_line(client: &mut Client, rx: &Receiver, line: String) - } for msg in &new_history { if msg.sender.eq_ignore_ascii_case(&username) { - info!("*[{}]{}: {}", msg.time.format("%H:%M %d.%m.%y"), msg.sender, msg.message) + info!("*[{}]{}: {}", msg.time.format("%H:%M:%S %d.%m.%y"), msg.sender, msg.message) } } if !new_history.is_empty() && ask_confirmation(rx, "Do you want to mark all unread messages as read now?").await { @@ -584,7 +597,7 @@ async fn handle_line(client: &mut Client, rx: &Receiver, line: String) - if sender.eq_ignore_ascii_case(&username) { let result = client.move_newest_pm_to_history().await; if let Ok(msg) = result { - info!("[{}]{}: {}", msg.time.format("%H:%M %d.%m.%y"), msg.sender, msg.message) + info!("[{}]{}: {}", msg.time.format("%H:%M:%S %d.%m.%y"), msg.sender, msg.message) } else { handle_error(&result); } diff --git a/banklib/src/extended.rs b/banklib/src/extended.rs index 8bc3f97..14123bf 100644 --- a/banklib/src/extended.rs +++ b/banklib/src/extended.rs @@ -124,8 +124,9 @@ impl Client { pub async fn register(&mut self, credentials: Credentials) -> BankResult<(), BankError> { self.client.set_credentials(credentials.username.clone(), credentials.password.clone())?; - let (_, msg_type) = display_message(self.client.send_authenticated( + let (message, msg_type) = display_message(self.client.send_authenticated( AuthenticatedMessage::Register, check_message_id!(MsgType::RegisterSuccess | MsgType::RegisterFailUsernameTaken)).await?); + info!("{}", message); match msg_type { MsgType::RegisterSuccess => Ok(()), MsgType::RegisterFailUsernameTaken => Err(report!(BankError::AuthenticationError)),