more help system

pull/6/head
dvkt 5 years ago
parent d32a25a4a6
commit 84f5093531

@ -1,4 +1,14 @@
pub const GOPHERMAP: &str = "
pub fn lookup(name: &str) -> Option<&str> {
match name {
"" | "/" | "help" => Some(HELP),
"types" => Some(TYPES),
"nav" => Some(NAV),
"keys" => Some(KEYS),
_ => None,
}
}
pub const HELP: &str = "
i
i
i / / /
@ -28,11 +38,90 @@ iPress the # of a link to visit
ior select it. Use ENTER to open
ithe selected link.
i
iTo select a link, start typing.
iTo select a link by name, just
istart typing.
i
i ~ * ~
i
1about phetch /phlog help
1menu navigation /nav help
1gopher types /types help
1all keys /keys help
hvisit homepage URL:https://github.com/dvkt/phetch
i
";
pub const NAV: &str = "
i
i
i / / /
i ___ (___ ___ (___ ___ (___
i| )| )|___)| | | )
i|__/ | / |__ |__ |__ | /
i|
i
i ** menu navigation **
i
ithere are three ways to navigate
imenus in phetch:
i
1up & down arrows /nav help
i
iuse the up and down arrows or the
ictrl-p/ctrl-n combos to select menu
iitems. phetch will scroll for you,
ibut you can use page up & page down
ito jump by many lines quickly.
i
1number keys /nav help
i
iif there are few enough menu items,
ipressing a number key will open the
iitem immediately. otherwise, it'll
ibe selected.
i
1incremental search /nav help
i
ijust start typing. phetch will look
ifor the first case insensitive match
iand try to select it.
i
";
pub const TYPES: &str = "
i
i
i / / /
i ___ (___ ___ (___ ___ (___
i| )| )|___)| | | )
i|__/ | / |__ |__ |__ | /
i|
i
i ** gopher types **
i
iphetch supports these links:
i
0text files
1menu items
3errors
hexternal URLs
7search servers
8telnet launching
i
iand these download types:
i
4binhex
5dosfiles
6uuencoded files
9binaries
gGIFs
Iimages downloads
ssound files
ddocuments
i
iphetch does not support:
i
2CSO Entries
+Mirrors
TTelnet3270
i
";

@ -91,11 +91,23 @@ impl UI {
}
pub fn open(&mut self, url: &str) -> io::Result<()> {
// no open loops
if let Some(page) = self.pages.get(self.page) {
if &page.url() == url {
return Ok(());
}
}
// non-gopher URL
if !url.starts_with("gopher://") {
return open_external(url);
}
// on-line help
if url.starts_with("gopher://help/") {
return self.open_help(url);
}
// gopher URL
status(&format!(
"{}Loading...{}",
@ -114,6 +126,19 @@ impl UI {
.map_err(|e| io_error(format!("Error loading {}: {} ({:?})", url, e, e.kind())))
}
// open a phetch on-line help url, ex: gopher://help/1/types
pub fn open_help(&mut self, url: &str) -> io::Result<()> {
if let Some(source) = help::lookup(
&url.trim_start_matches("gopher://help/")
.trim_start_matches("1/"),
) {
self.add_page(Menu::from(url.to_string(), source.to_string()));
Ok(())
} else {
Err(gopher::io_error(format!("Help file not found: {}", url)))
}
}
pub fn render(&mut self) -> String {
if let Ok((cols, rows)) = termion::terminal_size() {
self.term_size(cols as usize, rows as usize);
@ -199,9 +224,7 @@ impl UI {
}
}
}
Action::Keypress(Key::Ctrl('h')) => {
self.add_page(Menu::from("help".into(), help::GOPHERMAP.into()));
}
Action::Keypress(Key::Ctrl('h')) => self.open("gopher://help/")?,
Action::Keypress(Key::Ctrl('u')) => {
if let Some(page) = self.pages.get(self.page) {
status(&format!("Current URL: {}", page.url()));

Loading…
Cancel
Save