external links

pull/6/head
dvkt 5 years ago
parent 01356d08fd
commit 00563c37ce

@ -65,13 +65,13 @@ pub fn type_for_char(c: char) -> Option<Type> {
}
}
// Fetches a URL and returns a raw Gopher response.
// Fetches a gopher URL and returns a raw Gopher response.
pub fn fetch_url(url: &str) -> io::Result<String> {
let (_, host, port, sel) = parse_url(url);
fetch(host, port, sel)
}
// Fetches a URL by its component parts and returns a raw Gopher response.
// Fetches a gopher URL by its component parts and returns a raw Gopher response.
pub fn fetch(host: &str, port: &str, selector: &str) -> io::Result<String> {
let mut body = String::new();
let selector = selector.replace('?', "\t"); // search queries

@ -39,23 +39,27 @@ fn main() {
return;
}
if !url.is_empty() && url.chars().nth(0).unwrap() == '-' {
if !url.is_empty() && url.starts_with('-') {
eprintln!("unknown flag: {}\n", url);
print_usage();
exit(1);
}
let url = if url.starts_with("gopher://") {
url.to_string()
} else {
format!("gopher://{}", url)
};
let mut ui = UI::new();
ui.open(url)
.or_else(|e| Err(fatal(&format!("\r\x1b[91m{}\x1b[0m", e))));
ui.open(&url).or_else(|e| {
eprintln!("\r\x1b[91m{}\x1b[0m", e);
exit(1);
Err(e)
});
ui.run();
}
fn fatal(s: &str) {
eprintln!("{}", s);
exit(1);
}
fn print_version() {
println!("\x1b[93;1mphetch v0.0.1-dev\x1b[m");
}
@ -71,7 +75,13 @@ fn print_usage() {
}
fn print_raw(url: &str) {
gopher::fetch_url(url)
let url = if url.starts_with("gopher://") {
url.to_string()
} else {
format!("gopher://{}", url)
};
gopher::fetch_url(&url)
.and_then(|x| {
println!("{}", x);
Ok(())

@ -56,7 +56,7 @@ impl Menu {
// check for URL:<url> syntax
if parts.len() > 1 {
if &parts[1].chars().take(4).collect::<String>() == "URL:" {
if parts[1].starts_with("URL:") {
lines.push(Line {
name,
url: parts[1].chars().skip(4).collect::<String>(),

Loading…
Cancel
Save