From 939042a4c533695d043db1c09cc7b51c7653ca04 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 20 Mar 2021 15:00:49 -0700 Subject: [PATCH] skeleton code ready to start pluggin in async fetch calls to remote servers Some model still has to be built to put RTC somewhere Also stdout still requires async handling --- tui/.gitignore | 1 + tui/src/cache.rs | 18 +++++++++++++++--- tui/src/command.rs | 10 +++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tui/.gitignore b/tui/.gitignore index 2f7896d..9fbc864 100644 --- a/tui/.gitignore +++ b/tui/.gitignore @@ -1 +1,2 @@ target/ +tmp/ diff --git a/tui/src/cache.rs b/tui/src/cache.rs index 0781dec..5d63c7c 100644 --- a/tui/src/cache.rs +++ b/tui/src/cache.rs @@ -46,13 +46,25 @@ impl Default for Cache { impl Cache { pub async fn switch_channel(&mut self, id: u64) -> Command { - todo!() + if let Some(host) = self.active_server.as_ref() { + Command::Failure(format!("Not implemented yet!")) + } else { + Command::Failure(format!("No server selected yet")) + } } pub async fn switch_server(&mut self, host: &str) -> Command { - todo!() + if let Some(srv_cache) = self.servers.get(host) { + Command::Failure(format!("Not implemented yet!")) + } else { + Command::Failure(format!("Host {{ {} }} not found", host)) + } } pub async fn send_message(&mut self, id: &str) -> Command { - todo!() + if let Some(host) = self.active_server.as_ref() { + Command::Failure(format!("Not implemented yet!")) + } else { + Command::Failure(format!("No active server+channel to send message to")) + } } } diff --git a/tui/src/command.rs b/tui/src/command.rs index 9b673fe..9e315b2 100644 --- a/tui/src/command.rs +++ b/tui/src/command.rs @@ -10,7 +10,7 @@ pub enum Command { // Send regular message Message(String), // Command that failed with some message - Failure(&'static str), + Failure(String), } impl Command { @@ -46,19 +46,19 @@ impl Command { if s.starts_with("/chan") { match Command::parse_chan_id(s.as_ref()) { Some(id) => Command::Channel(id), - None => Command::Failure("no valid id(u64) provided") + None => Command::Failure("no valid id(u64) provided".into()) } } else if s.starts_with("/serv") { match Command::parse_hostname(s.as_ref()) { Some(hostname) => Command::Server(hostname), - None => Command::Failure("no hostname provided") + None => Command::Failure("no hostname provided".into()) } } else if s.starts_with("/help") { Command::Help } else { if s.starts_with("/") { - Command::Failure("command not found") + Command::Failure("command not found".into()) } else { Command::Message(s.into()) } @@ -87,7 +87,7 @@ impl Command { ]), Failure(msg) => Spans::from(vec![ Span::styled("! error ", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(*msg) + Span::raw(msg) ]) } }