mirror of
https://github.com/xvxx/phetch
synced 2024-11-05 00:00:58 +00:00
trim down
This commit is contained in:
parent
8eebcaaa8e
commit
852d3b3f83
16
src/main.rs
16
src/main.rs
@ -45,14 +45,8 @@ fn main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = if url.starts_with("gopher://") {
|
|
||||||
url.to_string()
|
|
||||||
} else {
|
|
||||||
format!("gopher://{}", url)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut ui = UI::new();
|
let mut ui = UI::new();
|
||||||
if let Err(e) = ui.open(&url) {
|
if let Err(e) = ui.open(url) {
|
||||||
ui::error(&e.to_string());
|
ui::error(&e.to_string());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -75,13 +69,7 @@ fn print_usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_raw(url: &str) {
|
fn print_raw(url: &str) {
|
||||||
let url = if url.starts_with("gopher://") {
|
gopher::fetch_url(url)
|
||||||
url.to_string()
|
|
||||||
} else {
|
|
||||||
format!("gopher://{}", url)
|
|
||||||
};
|
|
||||||
|
|
||||||
gopher::fetch_url(&url)
|
|
||||||
.and_then(|x| {
|
.and_then(|x| {
|
||||||
println!("{}", x);
|
println!("{}", x);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -395,7 +395,7 @@ impl Menu {
|
|||||||
}
|
}
|
||||||
Key::Backspace | Key::Delete => {
|
Key::Backspace | Key::Delete => {
|
||||||
if self.input.is_empty() {
|
if self.input.is_empty() {
|
||||||
Action::Back
|
Action::Keypress(key)
|
||||||
} else {
|
} else {
|
||||||
self.input.pop();
|
self.input.pop();
|
||||||
self.redraw_input()
|
self.redraw_input()
|
||||||
|
10
src/ui.rs
10
src/ui.rs
@ -30,9 +30,7 @@ pub struct UI {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
None, // do nothing
|
None, // do nothing
|
||||||
Back, // back in history
|
Open(String), // open url
|
||||||
Forward, // also history
|
|
||||||
Open(String), // url
|
|
||||||
Keypress(Key), // unknown keypress
|
Keypress(Key), // unknown keypress
|
||||||
Redraw, // redraw everything
|
Redraw, // redraw everything
|
||||||
Quit, // yup
|
Quit, // yup
|
||||||
@ -102,7 +100,7 @@ impl UI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// non-gopher URL
|
// non-gopher URL
|
||||||
if !url.starts_with("gopher://") {
|
if url.contains("://") && !url.starts_with("gopher://") {
|
||||||
return open_external(url);
|
return open_external(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,13 +258,13 @@ impl UI {
|
|||||||
Action::Error(e) => return Err(io_error(e)),
|
Action::Error(e) => return Err(io_error(e)),
|
||||||
Action::Redraw => self.dirty = true,
|
Action::Redraw => self.dirty = true,
|
||||||
Action::Open(url) => self.open(&url)?,
|
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 {
|
if self.page > 0 {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.page -= 1;
|
self.page -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Forward | Action::Keypress(Key::Right) => {
|
Action::Keypress(Key::Right) => {
|
||||||
if self.page < self.pages.len() - 1 {
|
if self.page < self.pages.len() - 1 {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.page += 1;
|
self.page += 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user