From 852d3b3f83e9924806d2ba411250930e75a8b0ad Mon Sep 17 00:00:00 2001 From: dvkt Date: Thu, 19 Dec 2019 21:44:21 -0800 Subject: [PATCH] trim down --- src/main.rs | 16 ++-------------- src/menu.rs | 2 +- src/ui.rs | 10 ++++------ 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 451eea8..9bef611 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,14 +45,8 @@ fn main() { exit(1); } - let url = if url.starts_with("gopher://") { - url.to_string() - } else { - format!("gopher://{}", url) - }; - let mut ui = UI::new(); - if let Err(e) = ui.open(&url) { + if let Err(e) = ui.open(url) { ui::error(&e.to_string()); exit(1); } @@ -75,13 +69,7 @@ fn print_usage() { } fn print_raw(url: &str) { - let url = if url.starts_with("gopher://") { - url.to_string() - } else { - format!("gopher://{}", url) - }; - - gopher::fetch_url(&url) + gopher::fetch_url(url) .and_then(|x| { println!("{}", x); Ok(()) diff --git a/src/menu.rs b/src/menu.rs index 366b837..3d3045a 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -395,7 +395,7 @@ impl Menu { } Key::Backspace | Key::Delete => { if self.input.is_empty() { - Action::Back + Action::Keypress(key) } else { self.input.pop(); self.redraw_input() diff --git a/src/ui.rs b/src/ui.rs index fea511b..5062f38 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -30,9 +30,7 @@ pub struct UI { #[derive(Debug)] pub enum Action { None, // do nothing - Back, // back in history - Forward, // also history - Open(String), // url + Open(String), // open url Keypress(Key), // unknown keypress Redraw, // redraw everything Quit, // yup @@ -102,7 +100,7 @@ impl UI { } // non-gopher URL - if !url.starts_with("gopher://") { + if url.contains("://") && !url.starts_with("gopher://") { return open_external(url); } @@ -260,13 +258,13 @@ impl UI { Action::Error(e) => return Err(io_error(e)), Action::Redraw => self.dirty = true, Action::Open(url) => self.open(&url)?, - Action::Back | Action::Keypress(Key::Left) | Action::Keypress(Key::Backspace) => { + Action::Keypress(Key::Left) | Action::Keypress(Key::Backspace) => { if self.page > 0 { self.dirty = true; self.page -= 1; } } - Action::Forward | Action::Keypress(Key::Right) => { + Action::Keypress(Key::Right) => { if self.page < self.pages.len() - 1 { self.dirty = true; self.page += 1;