really simple debugger logger, will remove at some point but it has use right now
This commit is contained in:
parent
bdd4a63a8d
commit
abd2537918
23
tui/src/log.rs
Normal file
23
tui/src/log.rs
Normal file
@ -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());
|
||||
}
|
@ -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<dyn Error>> {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user