fix scrolling, timeout

pull/6/head
dvkt 5 years ago
parent 929f385cb5
commit 3771d37754

@ -139,7 +139,6 @@ pub fn fetch_url(url: &str) -> Result<String> {
pub fn fetch(host: &str, port: &str, selector: &str) -> Result<String> {
get(host, port, selector).and_then(|mut stream| {
let mut body = String::new();
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION));
stream.read_to_string(&mut body)?;
Ok(body)
})
@ -160,8 +159,6 @@ pub fn download_url(url: &str) -> Result<(String, usize)> {
let mut keys = stdin.keys();
get(host, port, sel).and_then(|mut stream| {
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
let mut file = std::fs::OpenOptions::new()
.write(true)
.create(true)
@ -192,6 +189,7 @@ pub fn get(host: &str, port: &str, selector: &str) -> Result<TcpStream> {
.and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))
.and_then(|sock| TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION))
.and_then(|mut stream| {
stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?;
stream.write(format!("{}\r\n", selector).as_ref());
Ok(stream)
})

@ -125,12 +125,12 @@ i ** gopher types **
i
iphetch supports these links:
i
0text files /types help
1menu items /types help
0text files /Mirrors/RFC/rfc1436.txt fnord.one 65446
1menu items /lawn/ascii bitreich.org
3errors /types help
7search servers /types help
7search servers / forthworks.com 7001
8telnet links /types help
hexternal URLs /types help
hexternal URLs URL:https://en.wikipedia.org/wiki/Phetch/ help
i
iand these download types:
i

@ -88,7 +88,7 @@ impl Menu {
if let Some(&pos) = self.links.get(i) {
Some(if pos < self.scroll {
LinkPos::Above
} else if pos > self.scroll + self.rows() {
} else if pos > self.scroll + self.rows() - 2 {
LinkPos::Below
} else {
LinkPos::Visible
@ -368,7 +368,7 @@ impl Menu {
// no links or final link selected already
if self.links.is_empty() || new_link >= self.links.len() {
// if there are more rows, scroll down
if self.scroll < self.padding_bottom() {
if self.lines.len() >= self.rows() && self.scroll < self.padding_bottom() {
self.scroll += 1;
return Action::Redraw;
} else {
@ -410,7 +410,9 @@ impl Menu {
self.link = new_link;
// scroll if we are within 5 lines of the end
if let Some(&pos) = self.links.get(self.link) {
if pos >= self.scroll + self.rows() - 6 {
if self.lines.len() >= self.rows() // dont scroll if content too small
&& pos >= self.scroll + self.rows() - 6
{
self.scroll += 1;
}
}
@ -466,14 +468,17 @@ impl Menu {
if let Some(line) = self.link(self.link) {
let url = line.url.to_string();
let (typ, _, _, _) = gopher::parse_url(&url);
if typ == Type::Search {
if let Some(query) = ui::prompt(&format!("{}> ", line.name)) {
Action::Open(format!("{}?{}", url, query))
} else {
Action::None
match typ {
Type::Search => {
if let Some(query) = ui::prompt(&format!("{}> ", line.name)) {
Action::Open(format!("{}?{}", url, query))
} else {
Action::None
}
}
} else {
Action::Open(url)
Type::Error => Action::Error(line.name.to_string()),
Type::Telnet => Action::Error("Telnet support coming soon".into()),
_ => Action::Open(url),
}
} else {
Action::None

Loading…
Cancel
Save