pull/6/head
dvkt 5 years ago
parent 529336af2b
commit c53af4398d

@ -8,6 +8,8 @@ mod menu;
mod types;
mod ui;
use gopher::Type;
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
@ -23,9 +25,9 @@ fn main() {
print_usage();
return;
}
let mut ui = ui::UI::new();
ui.load(gopher::Type::Menu, host, port, selector);
let url = format!("{}:{}/1/{}", host, port, selector);
ui.load(url);
ui.run();
}

@ -13,9 +13,9 @@ pub struct MenuView {
#[derive(Debug)]
pub struct Menu {
url: String, // gopher url
lines: Vec<Line>, // lines
raw: String, // raw gopher response
url: String, // gopher url
}
#[derive(Debug)]
@ -128,15 +128,6 @@ impl Menu {
Self::parse(url, gopher_response)
}
// Loads a Menu given a URL.
pub fn load(host: &str, port: &str, selector: &str) -> io::Result<Menu> {
let url = format!("{}:{}{}", host, port, selector);
match gopher::fetch(host, port, selector) {
Ok(res) => Ok(Menu::from(url, res)),
Err(e) => Err(e),
}
}
// Parses the lines in a raw Gopher menu response.
fn parse(url: String, raw: String) -> Menu {
let mut lines = vec![];
@ -149,18 +140,23 @@ impl Menu {
if start {
line.0 = i + 1;
match c {
'0' => {
line.2 = Type::Text;
}
'1' => {
line.2 = Type::Menu;
}
'h' => {
line.2 = Type::HTML;
}
'i' => {
line.2 = Type::Info;
}
'0' => line.2 = Type::Text,
'1' => line.2 = Type::Menu,
'2' => panic!("CSOEntity not supported"), // TODO
'3' => line.2 = Type::Error,
'4' => panic!("Binhex not supported"), // TODO
'5' => panic!("DOSFile not supported"), // TODO
'6' => panic!("UUEncoded not supported"), // TODO
'7' => panic!("Search not supported"), // TODO
'8' => panic!("Telnet not supported"), // TODO
'9' => panic!("Binary not supported"), // TODO
'+' => panic!("Mirrors not supported"), // TODO
'g' => panic!("GIF not supported"), // TODO
'T' => panic!("Telnet3270 not supported"), // TODO
'h' => line.2 = Type::HTML,
'i' => line.2 = Type::Info,
's' => panic!("Sound not supported"), // TODO
'd' => panic!("Document not supported"), // TODO
'\n' => continue,
_ => {
eprintln!("unknown line type: {}", c);

@ -59,19 +59,15 @@ impl UI {
String::new()
}
pub fn load(&mut self, typ: Type, host: &str, port: &str, selector: &str) {
let response = gopher::fetch(host, port, selector)
pub fn load(&mut self, url: String) {
let (typ, host, port, sel) = gopher::parse_url(&url);
let response = gopher::fetch(host, port, sel)
.map_err(|e| {
eprintln!(
"\x1B[91merror loading \x1b[93m{}:{}{}: \x1B[0m{}",
host, port, selector, e
);
eprintln!("\x1B[91merror loading \x1b[93m{}: \x1B[0m{}", url, e);
std::process::exit(1);
})
.unwrap();
let url = format!("{}:{}{}", host, port, selector); // TODO
match typ {
Type::Menu => self.add_view(MenuView::from(url, response)),
// Type::Text => self.add_view(TextView::from(url, response)),

Loading…
Cancel
Save