Replace ansi_term, atty, terminal_size with termion

In the last patch, we added the termion dependency for the tui viewer.
With this patch, we remove the ansi_term, atty and terminal_size
dependencies and use termion instead.
This commit is contained in:
Robin Krahl 2020-10-08 10:32:05 +02:00
parent 8db34e33b2
commit b93dbca7f0
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8
6 changed files with 10 additions and 42 deletions

35
Cargo.lock generated
View File

@ -23,14 +23,6 @@ dependencies = [
"const-random 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "anyhow"
version = "1.0.31"
@ -58,16 +50,6 @@ dependencies = [
"wait-timeout 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hermit-abi 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "autocfg"
version = "1.0.0"
@ -478,14 +460,6 @@ dependencies = [
"unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hermit-abi"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.72 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "html2text"
version = "0.2.1"
@ -1019,10 +993,8 @@ dependencies = [
name = "rusty-man"
version = "0.3.0"
dependencies = [
"ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
"assert_cmd 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"cursive 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cursive-markup 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cursive_buffered_backend 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1042,7 +1014,7 @@ dependencies = [
"structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syntect 4.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"terminal_size 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"text-style 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1348,9 +1320,9 @@ name = "text-style"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cursive 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntect 4.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1613,12 +1585,10 @@ dependencies = [
"checksum adler 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
"checksum ahash 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
"checksum ahash 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0adac150c2dd5a9c864d054e07bda5e6bc010cd10036ea5f17e82a2f5867f735"
"checksum ansi_term 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
"checksum anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f"
"checksum arc-swap 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
"checksum array-macro 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "06e97b4e522f9e55523001238ac59d13a8603af57f69980de5d8de4bbbe8ada6"
"checksum assert_cmd 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c88b9ca26f9c16ec830350d309397e74ee9abdfd8eb1f71cb6ecc71a3fc818da"
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum base64 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
"checksum bincode 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
@ -1665,7 +1635,6 @@ dependencies = [
"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
"checksum hashbrown 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum hermit-abi 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151"
"checksum html2text 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a26379dcb715e237b96102a12b505c553e2bffa74bae2e54658748d298660ef1"
"checksum html5ever 0.25.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcf38a1a36118242d29b92e1b08ef84e67e4a5ed06e0a80be20e6a32bfed6b"
"checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"

View File

@ -16,9 +16,7 @@ license = "MIT"
exclude = [".builds/*", "tests/html/*", "tests/snapshots/*"]
[dependencies]
ansi_term = "0.12.1"
anyhow = "1.0.31"
atty = "0.2.14"
cursive_buffered_backend = "0.4"
cursive-markup = "0.1"
html2text = "0.2.1"
@ -29,7 +27,7 @@ merge = "0.1.0"
pager = "0.15.0"
serde_json = "1.0.56"
serde_tuple = "0.5.0"
terminal_size = "0.1.13"
termion = "1.5"
textwrap = "0.12.1"
toml = "0.5.6"
url = "2.1.1"
@ -60,7 +58,7 @@ features = ["parsing", "regex-onig", "assets", "dump-load"]
[dependencies.text-style]
version = "0.2.0"
features = ["ansi_term", "cursive", "syntect"]
features = ["cursive", "syntect", "termion"]
[dev-dependencies]
assert_cmd = "1.0.1"

View File

@ -204,7 +204,7 @@ fn select_item(
// If we are not on a TTY, we cant ask the user to select an item --> abort
anyhow::ensure!(
atty::is(atty::Stream::Stdin),
termion::is_tty(&io::stdin()),
"Found multiple matches for {}",
name
);

View File

@ -6,6 +6,7 @@ mod tui;
mod utils;
use std::fmt;
use std::io;
use crate::args;
use crate::doc;
@ -39,7 +40,7 @@ pub fn get_viewer(s: &str) -> anyhow::Result<Box<dyn Viewer>> {
}
pub fn get_default() -> Box<dyn Viewer> {
let text_mode = if atty::is(atty::Stream::Stdout) {
let text_mode = if termion::is_tty(&io::stdout()) {
text::TextMode::Rich
} else {
text::TextMode::Plain

View File

@ -117,7 +117,7 @@ fn render<'a, S>(s: S) -> io::Result<()>
where
S: Into<text_style::StyledStr<'a>>,
{
text_style::ansi_term::render(io::stdout(), s)
text_style::termion::render(io::stdout(), s)
}
fn render_iter<'a, I, S>(i: I) -> io::Result<()>
@ -125,5 +125,5 @@ where
I: IntoIterator<Item = S>,
S: Into<text_style::StyledStr<'a>>,
{
text_style::ansi_term::render_iter(io::stdout(), i)
text_style::termion::render_iter(io::stdout(), i)
}

View File

@ -435,7 +435,7 @@ impl text_renderer::TextDecorator for RichDecorator {
pub fn get_line_length(args: &args::ViewerArgs) -> usize {
if let Some(width) = args.width {
width
} else if let Some((terminal_size::Width(width), _)) = terminal_size::terminal_size() {
} else if let Ok((width, _)) = termion::terminal_size() {
cmp::min(width.into(), args.max_width.unwrap_or(100))
} else {
args.max_width.unwrap_or(100)