mirror of
https://github.com/xvxx/phetch
synced 2024-11-10 13:10:54 +00:00
whoops
This commit is contained in:
parent
529336af2b
commit
c53af4398d
@ -8,6 +8,8 @@ mod menu;
|
|||||||
mod types;
|
mod types;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
|
use gopher::Type;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
if args.len() < 2 {
|
if args.len() < 2 {
|
||||||
@ -23,9 +25,9 @@ fn main() {
|
|||||||
print_usage();
|
print_usage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ui = ui::UI::new();
|
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();
|
ui.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
src/menu.rs
40
src/menu.rs
@ -13,9 +13,9 @@ pub struct MenuView {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Menu {
|
pub struct Menu {
|
||||||
|
url: String, // gopher url
|
||||||
lines: Vec<Line>, // lines
|
lines: Vec<Line>, // lines
|
||||||
raw: String, // raw gopher response
|
raw: String, // raw gopher response
|
||||||
url: String, // gopher url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -128,15 +128,6 @@ impl Menu {
|
|||||||
Self::parse(url, gopher_response)
|
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.
|
// Parses the lines in a raw Gopher menu response.
|
||||||
fn parse(url: String, raw: String) -> Menu {
|
fn parse(url: String, raw: String) -> Menu {
|
||||||
let mut lines = vec![];
|
let mut lines = vec![];
|
||||||
@ -149,18 +140,23 @@ impl Menu {
|
|||||||
if start {
|
if start {
|
||||||
line.0 = i + 1;
|
line.0 = i + 1;
|
||||||
match c {
|
match c {
|
||||||
'0' => {
|
'0' => line.2 = Type::Text,
|
||||||
line.2 = Type::Text;
|
'1' => line.2 = Type::Menu,
|
||||||
}
|
'2' => panic!("CSOEntity not supported"), // TODO
|
||||||
'1' => {
|
'3' => line.2 = Type::Error,
|
||||||
line.2 = Type::Menu;
|
'4' => panic!("Binhex not supported"), // TODO
|
||||||
}
|
'5' => panic!("DOSFile not supported"), // TODO
|
||||||
'h' => {
|
'6' => panic!("UUEncoded not supported"), // TODO
|
||||||
line.2 = Type::HTML;
|
'7' => panic!("Search not supported"), // TODO
|
||||||
}
|
'8' => panic!("Telnet not supported"), // TODO
|
||||||
'i' => {
|
'9' => panic!("Binary not supported"), // TODO
|
||||||
line.2 = Type::Info;
|
'+' => 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,
|
'\n' => continue,
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("unknown line type: {}", c);
|
eprintln!("unknown line type: {}", c);
|
||||||
|
12
src/ui.rs
12
src/ui.rs
@ -59,19 +59,15 @@ impl UI {
|
|||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(&mut self, typ: Type, host: &str, port: &str, selector: &str) {
|
pub fn load(&mut self, url: String) {
|
||||||
let response = gopher::fetch(host, port, selector)
|
let (typ, host, port, sel) = gopher::parse_url(&url);
|
||||||
|
let response = gopher::fetch(host, port, sel)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
eprintln!(
|
eprintln!("\x1B[91merror loading \x1b[93m{}: \x1B[0m{}", url, e);
|
||||||
"\x1B[91merror loading \x1b[93m{}:{}{}: \x1B[0m{}",
|
|
||||||
host, port, selector, e
|
|
||||||
);
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let url = format!("{}:{}{}", host, port, selector); // TODO
|
|
||||||
|
|
||||||
match typ {
|
match typ {
|
||||||
Type::Menu => self.add_view(MenuView::from(url, response)),
|
Type::Menu => self.add_view(MenuView::from(url, response)),
|
||||||
// Type::Text => self.add_view(TextView::from(url, response)),
|
// Type::Text => self.add_view(TextView::from(url, response)),
|
||||||
|
Loading…
Reference in New Issue
Block a user