pull/6/head
dvkt 5 years ago
parent fa14ba532e
commit ce0ef445b6

@ -94,7 +94,7 @@ pub fn fetch(host: &str, port: &str, selector: &str) -> io::Result<String> {
.and_then(|mut socks| {
socks
.next()
.ok_or(io_error("Can't create socket".to_string()))
.ok_or_else(|| io_error("Can't create socket".to_string()))
.and_then(|sock| {
TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)
.and_then(|mut stream| {

@ -186,7 +186,7 @@ impl Menu {
fn action_page_down(&mut self) -> Action {
let lines = self.lines.len();
if lines < self.rows() {
if self.links.len() > 0 {
if !self.links.is_empty() {
self.link = self.links.len() - 1;
return Action::Redraw;
}
@ -541,16 +541,14 @@ impl Menu {
}
// check for URL:<url> syntax
if parts.len() > 1 {
if parts[1].starts_with("URL:") {
lines.push(Line {
name,
url: parts[1].trim_start_matches("URL:").to_string(),
typ,
link,
});
continue;
}
if parts.len() > 1 && parts[1].starts_with("URL:") {
lines.push(Line {
name,
url: parts[1].trim_start_matches("URL:").to_string(),
typ,
link,
});
continue;
}
// assemble regular, gopher-style URL
@ -571,7 +569,7 @@ impl Menu {
url.push_str("/");
url.push(first_char);
// add trailing / if the selector is blank
if parts.len() == 0 || parts.len() > 1 && parts[1].len() == 0 {
if parts.is_empty() || parts.len() > 1 && parts[1].is_empty() {
url.push('/');
}
}

@ -90,7 +90,7 @@ impl UI {
termion::cursor::Goto(1, 1),
termion::cursor::Hide,
self.render(),
self.render_status().unwrap_or("".into()),
self.render_status().unwrap_or_else(|| "".into()),
);
self.dirty = false;
@ -112,7 +112,7 @@ impl UI {
// no open loops
if let Some(page) = self.views.get(self.focused) {
if &page.url() == url {
if page.url() == url {
return Ok(());
}
}
@ -145,7 +145,7 @@ impl UI {
let (spintx, spinrx) = mpsc::channel();
thread::spawn(move || loop {
for i in 0..=3 {
if let Ok(_) = spinrx.try_recv() {
if spinrx.try_recv().is_ok() {
return;
}
print!(
@ -294,7 +294,7 @@ impl UI {
if let Ok(key) = stdin()
.keys()
.nth(0)
.ok_or(Action::Error("stdin.keys() error".to_string()))
.ok_or_else(|| Action::Error("stdin.keys() error".to_string()))
{
if let Ok(key) = key {
return page.respond(key);
@ -334,8 +334,8 @@ impl UI {
}
Action::Keypress(Key::Ctrl('r')) => {
if let Some(page) = self.views.get(self.focused) {
let url = page.url().to_string();
let raw = page.raw().to_string();
let url = page.url();
let raw = page.raw();
self.add_page(Box::new(Text::from(url, raw)));
}
}
@ -351,13 +351,15 @@ impl UI {
Action::Keypress(Key::Ctrl('h')) => self.open("gopher://help/")?,
Action::Keypress(Key::Ctrl('u')) => {
if let Some(page) = self.views.get(self.focused) {
self.set_status(format!("Current URL: {}", page.url()));
let url = page.url();
self.set_status(format!("Current URL: {}", url));
}
}
Action::Keypress(Key::Ctrl('y')) => {
if let Some(page) = self.views.get(self.focused) {
copy_to_clipboard(&page.url())?;
self.set_status(format!("Copied {} to clipboard.", page.url()));
let url = page.url();
copy_to_clipboard(&url)?;
self.set_status(format!("Copied {} to clipboard.", url));
}
}
_ => (),

Loading…
Cancel
Save