From abd2537918df3f4aea65bea4ecd6b4e03c2f49c8 Mon Sep 17 00:00:00 2001 From: shockrah Date: Fri, 9 Apr 2021 21:55:04 -0700 Subject: [PATCH] really simple debugger logger, will remove at some point but it has use right now --- tui/src/log.rs | 23 +++++++++++++++++++++++ tui/src/main.rs | 16 ++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tui/src/log.rs diff --git a/tui/src/log.rs b/tui/src/log.rs new file mode 100644 index 0000000..6d4e81e --- /dev/null +++ b/tui/src/log.rs @@ -0,0 +1,23 @@ +use crate::api_types as api; +use std::fs::OpenOptions; +use std::io::prelude::*; + +const LOG_FILE: &'static str = "tui.log"; + +pub fn file(data: &api::Message) { + let mut file = OpenOptions::new() + .append(true) + .create(true) + .open(LOG_FILE).unwrap(); + + let _ = file.write(format!("{:?}", data).as_bytes()); +} + +pub fn plain(s: String) { + let mut file = OpenOptions::new() + .append(true) + .create(true) + .open(LOG_FILE).unwrap(); + + let _ = file.write(format!("{}\n", s).as_bytes()); +} diff --git a/tui/src/main.rs b/tui/src/main.rs index f33e0ed..cdd4c3c 100644 --- a/tui/src/main.rs +++ b/tui/src/main.rs @@ -2,6 +2,7 @@ mod util; mod command; mod config; mod api_types; +mod log; mod cache; mod net; #[macro_use] mod common; @@ -223,8 +224,19 @@ async fn main() -> Result<(), Box> { let cmd = Command::from(trimmed); app.messages.lock().unwrap().push(match cmd { // only for networked commands do we need to touch cache - Command::Channel(id) => app.cache.switch_channel(id).await, - Command::Server(host) => app.cache.switch_server(&host).await, + Command::Channel(id) => { + app.cache.switch_channel(id).await + }, + Command::Server(url_portion) => { + if let Some((url, id)) = app.cache.find_serv(url_portion) { + let (cmd, jwt) = app.cache.switch_server(url.as_str()).await; + let url = net::ws_url(url.as_str(), jwt); + app.cache = app.cache.setup_websocket(url, id).await; + cmd + } else { + Command::Failure("No server found".into()) + } + }, Command::Message(msg) => app.cache.send_message(&msg).await, Command::ListHost => app.cache.list_hosts(), Command::ListChannel => app.cache.list_channels().await,