just for fun

pull/14/head
dvkt 4 years ago
parent 93fc673131
commit 30ded8ed69

@ -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

@ -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.

@ -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<Config> {
}
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");

@ -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

@ -293,19 +293,21 @@ impl UI {
self.status = status;
}
fn render_tls_status(&self) -> Option<String> {
fn render_conn_status(&self) -> Option<String> {
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,
)
}

Loading…
Cancel
Save