From a098121ab8bb2724c0cd316469562ba45e41bf49 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 4 Apr 2021 14:17:39 -0700 Subject: [PATCH] * Messages now grow from the top to the bottom(new messages ontop) + Option to enable/disable message-box borders * Switching over to using bold! macro where applicable (especially in command.rs) This change mostly reduces the eyesoreness of the termion code --- tui/src/command.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tui/src/command.rs b/tui/src/command.rs index 9e315b2..d3daa47 100644 --- a/tui/src/command.rs +++ b/tui/src/command.rs @@ -1,3 +1,4 @@ +use crate::{bold, normal}; use tui::text::{Span, Spans}; use tui::style::{Style, Modifier}; @@ -7,6 +8,9 @@ pub enum Command { Channel(u64), // Choose server based on hostname Server(String), + // List out available hosts + ListHost, + Text(String), // Send regular message Message(String), // Command that failed with some message @@ -43,6 +47,7 @@ impl Command { pub fn from(s: String) -> Command { let s = s.trim(); + // NOTE: could probably do this smarter but a handful of string comparisons is fine too if s.starts_with("/chan") { match Command::parse_chan_id(s.as_ref()) { Some(id) => Command::Channel(id), @@ -55,6 +60,8 @@ impl Command { } } else if s.starts_with("/help") { Command::Help + } else if s.starts_with("/lh") { + Command::ListHost } else { if s.starts_with("/") { @@ -68,26 +75,26 @@ impl Command { pub fn styled(&self) -> Spans { use Command::*; return match self { - Help => Spans::from(vec![ - Span::styled("! /help\n", Style::default().add_modifier(Modifier::BOLD)), - Span::styled("! /channel ", Style::default().add_modifier(Modifier::BOLD)), - Span::styled("! /server ", Style::default().add_modifier(Modifier::BOLD)), - ]), + Help => Spans::from(bold!("! /help ! /channel ! /server ")), + Text(s) => Spans::from(vec![normal!(s)]), Channel(id) => Spans::from(vec![ - Span::styled(format!("! /channel "), Style::default().add_modifier(Modifier::BOLD)), - Span::raw(format!("{}", id)), + bold!("! /channel "), + normal!(format!("{}", id)), ]), Server(hostname) => Spans::from(vec![ - Span::styled("! /server ", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(hostname) + bold!("! /server "), + normal!(hostname) + ]), + ListHost => Spans::from(vec![ + bold!("! /lh"), ]), Message(msg) => Spans::from(vec![ - Span::styled("(You) ", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(msg) + bold!("(You) "), + normal!(msg) ]), Failure(msg) => Spans::from(vec![ - Span::styled("! error ", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(msg) + bold!("! error "), + normal!(msg) ]) } }