phetch urls, not help url

pull/6/head
dvkt 5 years ago
parent 57096fc8b9
commit 864786415f

@ -242,6 +242,8 @@ mod tests {
"gopher://9999:aaaa::abab:baba:aaaa:9999", "gopher://9999:aaaa::abab:baba:aaaa:9999",
"[2001:2099:dead:beef:0000", "[2001:2099:dead:beef:0000",
"::1", "::1",
"ssh://kiosk@bitreich.org",
"https://github.com/dvkt/phetch",
]; ];
let (typ, host, port, sel) = parse_url(urls[0]); let (typ, host, port, sel) = parse_url(urls[0]);
@ -315,5 +317,17 @@ mod tests {
assert_eq!(host, "::1"); assert_eq!(host, "::1");
assert_eq!(port, "70"); assert_eq!(port, "70");
assert_eq!(sel, "/"); assert_eq!(sel, "/");
let (typ, host, port, sel) = parse_url(urls[12]);
assert_eq!(typ, Type::HTML);
assert_eq!(host, "kiosk@bitreich.org");
assert_eq!(port, "70");
assert_eq!(sel, "");
let (typ, host, port, sel) = parse_url(urls[13]);
assert_eq!(typ, Type::HTML);
assert_eq!(host, "https://github.com/dvkt/phetch");
assert_eq!(port, "70");
assert_eq!(sel, "");
} }
} }

@ -3,13 +3,13 @@ use history;
pub fn lookup(name: &str) -> Option<String> { pub fn lookup(name: &str) -> Option<String> {
Some(match name { Some(match name {
"" | "/" | "help" => format!("{}{}", HEADER, HELP), "" | "/" | "home" | "home/" => format!("{}{}", HEADER, HOME),
"home" => format!("{}{}", HEADER, HOME), "help" | "help/" => format!("{}{}", HEADER, HELP),
"history" => history::as_raw_menu(), "history" => history::as_raw_menu(),
"bookmarks" => bookmarks::as_raw_menu(), "bookmarks" => bookmarks::as_raw_menu(),
"keys" => format!("{}{}", HEADER, KEYS), "help/keys" => format!("{}{}", HEADER, KEYS),
"nav" => format!("{}{}", HEADER, NAV), "help/nav" => format!("{}{}", HEADER, NAV),
"types" => format!("{}{}", HEADER, TYPES), "help/types" => format!("{}{}", HEADER, TYPES),
_ => return None, _ => return None,
}) })
} }
@ -35,23 +35,23 @@ i
i i
i ~ * ~ i ~ * ~
i i
1phetch help \x1b[90mctrl-h / help 1show help \x1b[90mctrl-h /help phetch
1show history \x1b[90mctrl-a /history help 1show history \x1b[90mctrl-a /history phetch
1show bookmarks \x1b[90mctrl-b /bookmarks help 1show bookmarks \x1b[90mctrl-b /bookmarks phetch
i\x1b[0m i\x1b[0m
"; ";
pub const HELP: &str = " pub const HELP: &str = "
i ** help topics ** i ** help topics **
i i
1keyboard shortcuts /keys help 1keyboard shortcuts /help/keys phetch
1menu navigation /nav help 1menu navigation /help/nav phetch
1gopher types /types help 1gopher types /help/types phetch
i i
i ~ * ~ i ~ * ~
i i
1start screen /home help 1start screen /home phetch
1history /history help 1history /history phetch
hphetch webpage URL:https://github.com/dvkt/phetch hphetch webpage URL:https://github.com/dvkt/phetch
i i
"; ";
@ -88,7 +88,7 @@ i
ithere are three ways to navigate ithere are three ways to navigate
imenus in phetch: imenus in phetch:
i i
1up & down arrows /nav help 1up & down arrows /help/nav phetch
i i
iuse the up and down arrows or the iuse the up and down arrows or the
ictrl-p/ctrl-n combos to select menu ictrl-p/ctrl-n combos to select menu
@ -97,14 +97,14 @@ ior you can use page up & page down
i(or - and spacebar) to jump by many i(or - and spacebar) to jump by many
ilines quickly. ilines quickly.
i i
1number keys /nav help 1number keys /help/nav phetch
i i
iif there are few enough menu items, iif there are few enough menu items,
ipressing a number key will open the ipressing a number key will open the
iitem immediately. otherwise, it'll iitem immediately. otherwise, it'll
ibe selected. use enter to open it. ibe selected. use enter to open it.
i i
1incremental search /nav help 1incremental search /help/nav phetch
i i
ijust start typing. phetch will look ijust start typing. phetch will look
ifor the first case insensitive match ifor the first case insensitive match
@ -130,26 +130,26 @@ iphetch supports these links:
i i
0text files /Mirrors/RFC/rfc1436.txt fnord.one 65446 0text files /Mirrors/RFC/rfc1436.txt fnord.one 65446
1menu items /lawn/ascii bitreich.org 1menu items /lawn/ascii bitreich.org
3errors /types help 3errors /help/types phetch
7search servers / forthworks.com 7001 7search servers / forthworks.com 7001
8telnet links /types help 8telnet links /help/types phetch
hexternal URLs URL:https://en.wikipedia.org/wiki/Phetch/ help hexternal URLs URL:https://en.wikipedia.org/wiki/Phetch phetch
i i
iand these download types: iand these download types:
i i
4binhex /types help 4binhex /help/types phetch
5dosfiles /types help 5dosfiles /help/types phetch
6uuencoded files /types help 6uuencoded files /help/types phetch
9binaries /types help 9binaries /help/types phetch
gGIFs /types help gGIFs /help/types phetch
Iimages downloads /types help Iimages downloads /help/types phetch
ssound files /types help ssound files /help/types phetch
ddocuments /types help ddocuments /help/types phetch
i i
iphetch does not support: iphetch does not support:
i i
2CSO Entries /types help 2CSO Entries /help/types phetch
+Mirrors /types help +Mirrors /help/types phetch
TTelnet3270 /types help TTelnet3270 /help/types phetch
i i
"; ";

@ -7,7 +7,7 @@ use std::process::exit;
fn main() { fn main() {
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
let url = if args.len() < 2 { let url = if args.len() < 2 {
"gopher://help/1/home" "gopher://phetch/1/home"
} else { } else {
args.get(1).unwrap() args.get(1).unwrap()
}; };

@ -483,14 +483,12 @@ impl Menu {
Type::Telnet => Action::Error("Telnet support coming soon".into()), Type::Telnet => Action::Error("Telnet support coming soon".into()),
_ => { _ => {
// don't record internal urls // don't record internal urls
if host != "help" { if host != "phetch" && (typ == Type::Text || typ == Type::Menu) {
let hurl = url.to_string(); let hurl = url.to_string();
let hname = line.name.clone(); let hname = line.name.clone();
thread::spawn(move || history::save(&hname, &hurl)); thread::spawn(move || history::save(&hname, &hurl));
Action::Open(url)
} else {
Action::None
} }
Action::Open(url)
} }
} }
} else { } else {
@ -764,9 +762,12 @@ i Err bitreich.org 70"
); );
assert_eq!(menu.link(2).unwrap().url, "gopher://bitreich.org/1/onion"); assert_eq!(menu.link(2).unwrap().url, "gopher://bitreich.org/1/onion");
assert_eq!(menu.link(3).unwrap().url, "gopher://bitreich.org/1/kiosk"); assert_eq!(menu.link(3).unwrap().url, "gopher://bitreich.org/1/kiosk");
assert_eq!(menu.link(4).unwrap().url, "ssh://kiosk@bitreich.org");
assert_eq!(menu.link, 0); assert_eq!(menu.link, 0);
let ssh = menu.link(4).unwrap();
assert_eq!(ssh.url, "ssh://kiosk@bitreich.org");
assert_eq!(ssh.typ, Type::HTML);
menu.action_down(); menu.action_down();
assert_eq!(menu.link, 1); assert_eq!(menu.link, 1);
assert_eq!(menu.link(menu.link).unwrap().link, 1); assert_eq!(menu.link(menu.link).unwrap().link, 1);

@ -135,8 +135,8 @@ impl UI {
fn fetch(&mut self, url: &str) -> Result<Page> { fn fetch(&mut self, url: &str) -> Result<Page> {
// on-line help // on-line help
if url.starts_with("gopher://help/") { if url.starts_with("gopher://phetch/") {
return self.fetch_help(url); return self.fetch_internal(url);
} }
// request thread // request thread
let thread_url = url.to_string(); let thread_url = url.to_string();
@ -149,15 +149,15 @@ impl UI {
} }
} }
// get Menu for on-line help url, ex: gopher://help/1/types // get Menu for on-line help, home page, etc, ex: gopher://home/1/help/types
fn fetch_help(&mut self, url: &str) -> Result<Page> { fn fetch_internal(&mut self, url: &str) -> Result<Page> {
if let Some(source) = help::lookup( if let Some(source) = help::lookup(
&url.trim_start_matches("gopher://help/") &url.trim_start_matches("gopher://phetch/")
.trim_start_matches("1/"), .trim_start_matches("1/"),
) { ) {
Ok(Box::new(Menu::from(url.to_string(), source))) Ok(Box::new(Menu::from(url.to_string(), source)))
} else { } else {
Err(error!("Help file not found: {}", url)) Err(error!("phetch URL not found: {}", url))
} }
} }
@ -322,9 +322,9 @@ impl UI {
} }
} }
} }
Action::Keypress(Key::Ctrl('h')) => self.open("gopher://help/")?, Action::Keypress(Key::Ctrl('h')) => self.open("gopher://phetch/1/help")?,
Action::Keypress(Key::Ctrl('a')) => self.open("gopher://help/1/history")?, Action::Keypress(Key::Ctrl('a')) => self.open("gopher://phetch/1/history")?,
Action::Keypress(Key::Ctrl('b')) => self.open("gopher://help/1/bookmarks")?, Action::Keypress(Key::Ctrl('b')) => self.open("gopher://phetch/1/bookmarks")?,
Action::Keypress(Key::Ctrl('s')) => { Action::Keypress(Key::Ctrl('s')) => {
if let Some(page) = self.views.get(self.focused) { if let Some(page) = self.views.get(self.focused) {
let url = page.url(); let url = page.url();

Loading…
Cancel
Save