From 30ded8ed69c33eb6279b18455262ac84727d4f2c Mon Sep 17 00:00:00 2001 From: dvkt Date: Fri, 10 Jan 2020 19:55:17 -0800 Subject: [PATCH] just for fun --- README.md | 1 + doc/phetch.1.md | 3 +++ src/config.rs | 9 ++++++++- src/main.rs | 4 +++- src/ui.rs | 10 ++++++---- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 110046d..45174ce 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ the gophersphere. -p, --print Print rendered Gopher response only -l, --local Connect to 127.0.0.1:7070 + --emoji Show TLS/Tor status as emoji. -h, --help Show this screen -v, --version Show phetch version diff --git a/doc/phetch.1.md b/doc/phetch.1.md index 3b363ae..1882c65 100644 --- a/doc/phetch.1.md +++ b/doc/phetch.1.md @@ -27,6 +27,9 @@ phetch - quick lil gopher client Set the TOR_PROXY env variable to use an address other than the Tor default of 127.0.0.1:9050. +*--emoji* + Show TLS/Tor status as emoji. + *-h*, *--help* Print a help summary and exit. diff --git a/src/config.rs b/src/config.rs index c0319f9..f604d4b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,6 +27,9 @@ tor no # Always start in wide mode. (--wide) wide no + +# Use emoji indicators for TLS & Tor. (--emoji) +emoji no "; #[derive(Debug)] @@ -35,6 +38,7 @@ pub struct Config { pub tls: bool, pub tor: bool, pub wide: bool, + pub emoji: bool, } impl Default for Config { @@ -44,6 +48,7 @@ impl Default for Config { tls: false, tor: false, wide: false, + emoji: false, } } } @@ -97,6 +102,7 @@ pub fn parse(text: &str) -> Result { } match key { "start" => cfg.start = val.into(), + "emoji" => cfg.emoji = to_bool(val)?, "tls" => cfg.tls = to_bool(val)?, "tor" => cfg.tor = to_bool(val)?, "wide" => cfg.wide = to_bool(val)?, @@ -128,6 +134,7 @@ mod tests { assert_eq!(config.tls, false); assert_eq!(config.tor, false); assert_eq!(config.wide, false); + assert_eq!(config.emoji, false); assert_eq!(config.start, "gopher://phetch/1/home"); } @@ -166,7 +173,7 @@ mod tests { } #[test] fn test_no_dupe_keys() { - let res = parse("tls false\nwide no\ntls yes"); + let res = parse("tls false\nwide no\nemoji yes\ntls yes"); assert_eq!(res.is_err(), true); let e = res.unwrap_err(); assert_eq!(format!("{}", e), "Duplicate key on line 3: tls"); diff --git a/src/main.rs b/src/main.rs index 6c3c215..c558162 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,7 @@ fn run() -> i32 { mode = Mode::Print; } "-l" | "--local" | "-local" => cfg.start = "gopher://127.0.0.1:7070".into(), + "--emoji" | "-emoji" => cfg.emoji = true, "-t" | "--tls" | "-tls" => { cfg.tls = true; if cfg!(feature = "disable-tls") { @@ -126,7 +127,7 @@ fn print_usage() { print_version(); println!( " -Usage: +Usage: phetch [options] Launch phetch in interactive mode phetch [options] [url] Open Gopher URL in interactive mode @@ -141,6 +142,7 @@ Options: -p, --print Print rendered Gopher response only -l, --local Connect to 127.0.0.1:7070 + --emoji Show TLS/Tor status as emoji. -h, --help Show this screen -v, --version Show phetch version diff --git a/src/ui.rs b/src/ui.rs index de6cb64..013fe0b 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -293,19 +293,21 @@ impl UI { self.status = status; } - fn render_tls_status(&self) -> Option { + fn render_conn_status(&self) -> Option { let page = self.views.get(self.focused)?; if page.is_tls() { + let status = color!("TLS", Black, GreenBG); return Some(format!( "{}{}", termion::cursor::Goto(self.cols() - 3, self.rows()), - color!("TLS", Black, GreenBG), + if self.config.emoji { "🔒" } else { &status }, )); } else if page.is_tor() { + let status = color!("TOR", Bold, White, MagentaBG); return Some(format!( "{}{}", termion::cursor::Goto(self.cols() - 3, self.rows()), - color!("TOR", Bold, White, MagentaBG), + if self.config.emoji { "🧅" } else { &status }, )); } None @@ -318,7 +320,7 @@ impl UI { termion::cursor::Goto(1, self.rows()), termion::clear::CurrentLine, self.status, - self.render_tls_status().unwrap_or_else(|| "".into()), + self.render_conn_status().unwrap_or_else(|| "".into()), color::Reset, ) }