📎📎📎

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};
#[cfg(not(test))]
use atty;
/// The error returned if something goes awry while parsing the
/// command line arguments.
#[derive(Debug)]

@ -37,10 +37,7 @@ impl Type {
/// Text document?
pub fn is_text(self) -> bool {
match self {
Type::Text | Type::Xml => true,
_ => false,
}
matches!(self, Type::Text | Type::Xml)
}
/// HTML link?
@ -60,36 +57,33 @@ impl Type {
/// Is this something we can download?
pub fn is_download(self) -> bool {
match self {
matches!(
self,
Type::Binhex
| Type::DOSFile
| Type::UUEncoded
| Type::Binary
| Type::GIF
| Type::Image
| Type::PNG
| Type::Sound
| Type::Video
| Type::Calendar
| Type::Document => true,
_ => false,
}
| Type::DOSFile
| Type::UUEncoded
| Type::Binary
| Type::GIF
| Type::Image
| Type::PNG
| Type::Sound
| Type::Video
| Type::Calendar
| Type::Document
)
}
/// Check if media to open in player
pub fn is_media(self) -> bool {
match self {
Type::Sound | Type::Video => true,
_ => false,
}
matches!(self, Type::Sound | Type::Video)
}
/// Is this a type phetch supports?
pub fn is_supported(self) -> bool {
match self {
Type::CSOEntity | Type::Mirror | Type::Telnet3270 | Type::Mailbox => false,
_ => true,
}
!matches!(
self,
Type::CSOEntity | Type::Mirror | Type::Telnet3270 | Type::Mailbox
)
}
/// 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
// 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 iter = raw[start..text_end].char_indices();
visible_len = 0;
@ -1010,21 +1010,17 @@ pub fn parse_line(start: usize, raw: &str) -> Option<LineSpan> {
if c == 'm' {
is_color = false;
}
} else {
if c == '\x1b' {
if let Some((_, '[')) = iter.next() {
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 c == '\x1b' {
if let Some((_, '[')) = iter.next() {
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;
}
}
}

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

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

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

Loading…
Cancel
Save