Skip to content

Commit 94cee26

Browse files
committed
#48 support feature isatty on stdout
1 parent 2e34704 commit 94cee26

File tree

3 files changed

+63
-56
lines changed

3 files changed

+63
-56
lines changed

Cargo.lock

Lines changed: 55 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ opt-level = 3
3030
[dependencies]
3131
clap = "2.31.1"
3232
ansi_term = "0.11"
33+
atty = "0.2"
3334

3435
[dev-dependencies]
3536
assert_cmd = "1.0.1"

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
extern crate ansi_term;
1616
extern crate clap;
1717

18+
use atty::Stream;
1819
use clap::ArgMatches;
1920
use std::env;
2021
use std::error::Error;
@@ -276,6 +277,12 @@ pub fn run(matches: ArgMatches) -> Result<(), Box<dyn Error>> {
276277
}
277278
}
278279

280+
// prevent term color codes being sent to stdout
281+
// test: cat Cargo.toml | target/debug/hx | more
282+
if !atty::is(Stream::Stdout) {
283+
colorize = false;
284+
}
285+
279286
// array output mode is mutually exclusive
280287
if let Some(array) = matches.value_of(ARG_ARR) {
281288
output_array(array, buf, truncate_len, column_width)?;

0 commit comments

Comments
 (0)