* 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
This commit is contained in:
shockrah 2021-04-04 14:17:39 -07:00
parent 6fff48cfab
commit a098121ab8

View File

@ -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 <u64>", Style::default().add_modifier(Modifier::BOLD)),
Span::styled("! /server <u64>", Style::default().add_modifier(Modifier::BOLD)),
]),
Help => Spans::from(bold!("! /help ! /channel <u64> ! /server <u64>")),
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)
])
}
}