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
This commit is contained in:
shockrah 2021-03-20 15:00:49 -07:00
parent 988aa9f155
commit 939042a4c5
3 changed files with 21 additions and 8 deletions

1
tui/.gitignore vendored
View File

@ -1 +1,2 @@
target/ target/
tmp/

View File

@ -46,13 +46,25 @@ impl Default for Cache {
impl Cache { impl Cache {
pub async fn switch_channel(&mut self, id: u64) -> Command { 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 { 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 { 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"))
}
} }
} }

View File

@ -10,7 +10,7 @@ pub enum Command {
// Send regular message // Send regular message
Message(String), Message(String),
// Command that failed with some message // Command that failed with some message
Failure(&'static str), Failure(String),
} }
impl Command { impl Command {
@ -46,19 +46,19 @@ impl Command {
if s.starts_with("/chan") { if s.starts_with("/chan") {
match Command::parse_chan_id(s.as_ref()) { match Command::parse_chan_id(s.as_ref()) {
Some(id) => Command::Channel(id), 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") { } else if s.starts_with("/serv") {
match Command::parse_hostname(s.as_ref()) { match Command::parse_hostname(s.as_ref()) {
Some(hostname) => Command::Server(hostname), Some(hostname) => Command::Server(hostname),
None => Command::Failure("no hostname provided") None => Command::Failure("no hostname provided".into())
} }
} else if s.starts_with("/help") { } else if s.starts_with("/help") {
Command::Help Command::Help
} }
else { else {
if s.starts_with("/") { if s.starts_with("/") {
Command::Failure("command not found") Command::Failure("command not found".into())
} else { } else {
Command::Message(s.into()) Command::Message(s.into())
} }
@ -87,7 +87,7 @@ impl Command {
]), ]),
Failure(msg) => Spans::from(vec![ Failure(msg) => Spans::from(vec![
Span::styled("! error ", Style::default().add_modifier(Modifier::BOLD)), Span::styled("! error ", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(*msg) Span::raw(msg)
]) ])
} }
} }