📎📎📎

pull/22/head
chris west 4 years ago
parent 80314f6bd6
commit 06344f734a

@ -7,9 +7,6 @@ use crate::{
}; };
use std::{error::Error, fmt, result::Result}; use std::{error::Error, fmt, result::Result};
#[cfg(not(test))]
use atty;
/// The error returned if something goes awry while parsing the /// The error returned if something goes awry while parsing the
/// command line arguments. /// command line arguments.
#[derive(Debug)] #[derive(Debug)]

@ -37,10 +37,7 @@ impl Type {
/// Text document? /// Text document?
pub fn is_text(self) -> bool { pub fn is_text(self) -> bool {
match self { matches!(self, Type::Text | Type::Xml)
Type::Text | Type::Xml => true,
_ => false,
}
} }
/// HTML link? /// HTML link?
@ -60,36 +57,33 @@ impl Type {
/// Is this something we can download? /// Is this something we can download?
pub fn is_download(self) -> bool { pub fn is_download(self) -> bool {
match self { matches!(
self,
Type::Binhex Type::Binhex
| Type::DOSFile | Type::DOSFile
| Type::UUEncoded | Type::UUEncoded
| Type::Binary | Type::Binary
| Type::GIF | Type::GIF
| Type::Image | Type::Image
| Type::PNG | Type::PNG
| Type::Sound | Type::Sound
| Type::Video | Type::Video
| Type::Calendar | Type::Calendar
| Type::Document => true, | Type::Document
_ => false, )
}
} }
/// Check if media to open in player /// Check if media to open in player
pub fn is_media(self) -> bool { pub fn is_media(self) -> bool {
match self { matches!(self, Type::Sound | Type::Video)
Type::Sound | Type::Video => true,
_ => false,
}
} }
/// Is this a type phetch supports? /// Is this a type phetch supports?
pub fn is_supported(self) -> bool { pub fn is_supported(self) -> bool {
match self { !matches!(
Type::CSOEntity | Type::Mirror | Type::Telnet3270 | Type::Mailbox => false, self,
_ => true, Type::CSOEntity | Type::Mirror | Type::Telnet3270 | Type::Mailbox
} )
} }
/// Gopher Item Type to RFC char. /// Gopher Item Type to RFC char.

@ -1000,7 +1000,7 @@ pub fn parse_line(start: usize, raw: &str) -> Option<LineSpan> {
// if this line contains colors, calculate the visible length and // if this line contains colors, calculate the visible length and
// where to truncate when abiding by `MAX_COLS` // where to truncate when abiding by `MAX_COLS`
if *&raw[start..text_end].contains("\x1b[") { if raw[start..text_end].contains("\x1b[") {
let mut is_color = false; let mut is_color = false;
let mut iter = raw[start..text_end].char_indices(); let mut iter = raw[start..text_end].char_indices();
visible_len = 0; visible_len = 0;
@ -1010,21 +1010,17 @@ pub fn parse_line(start: usize, raw: &str) -> Option<LineSpan> {
if c == 'm' { if c == 'm' {
is_color = false; is_color = false;
} }
} else { } else if c == '\x1b' {
if c == '\x1b' { if let Some((_, '[')) = iter.next() {
if let Some((_, '[')) = iter.next() { is_color = true;
is_color = true;
}
} else {
if visible_len < MAX_COLS {
truncated_len = i;
visible_len += 1;
} else {
truncated_len = i;
visible_len = MAX_COLS + 1;
break;
}
} }
} else if visible_len < MAX_COLS {
truncated_len = i;
visible_len += 1;
} else {
truncated_len = i;
visible_len = MAX_COLS + 1;
break;
} }
} }
} }

@ -5,7 +5,6 @@
use lazy_static::lazy_static; use lazy_static::lazy_static;
use libc::{cfmakeraw, tcgetattr, tcsetattr, termios as Termios, STDIN_FILENO, TCSANOW}; use libc::{cfmakeraw, tcgetattr, tcsetattr, termios as Termios, STDIN_FILENO, TCSANOW};
use std::{io, sync::Mutex}; use std::{io, sync::Mutex};
use termion;
pub use termion::cursor::Goto; pub use termion::cursor::Goto;
pub use termion::cursor::Hide as HideCursor; pub use termion::cursor::Hide as HideCursor;

@ -26,7 +26,6 @@ use crate::{
text::Text, text::Text,
utils, BUG_URL, utils, BUG_URL,
}; };
use lazy_static;
use std::{ use std::{
io::{stdin, stdout, Result, Write}, io::{stdin, stdout, Result, Write},
process::{self, Stdio}, process::{self, Stdio},
@ -236,7 +235,7 @@ impl UI {
gopher::download_url(&url, tls, tor, chan) gopher::download_url(&url, tls, tor, chan)
}) })
.and_then(|res| res) .and_then(|res| res)
.and_then(|(path, bytes)| { .map(|(path, bytes)| {
self.set_status( self.set_status(
format!( format!(
"Download complete! {} saved to {}", "Download complete! {} saved to {}",
@ -245,7 +244,6 @@ impl UI {
) )
.as_ref(), .as_ref(),
); );
Ok(())
}) })
} }

@ -33,11 +33,7 @@ pub enum Action {
impl Action { impl Action {
/// Is it Action::None? /// Is it Action::None?
pub fn is_none(&self) -> bool { pub fn is_none(&self) -> bool {
if let Action::None = self { matches!(self, Action::None)
true
} else {
false
}
} }
} }

Loading…
Cancel
Save