diff options
author | Julian Sitkevich <1553398+sitkevij@users.noreply.github.com> | 2020-11-22 09:42:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-22 09:42:47 -0800 |
commit | b0a844a83c9c15f2416fa7e5748347fbe1ee4a77 (patch) | |
tree | 1387bfc70dbe5a4da6680ae9650087a09f5d32c6 /src/lib.rs | |
parent | 2e34704eba10e0619d5ddcb5f98cce0d06f53d9e (diff) | |
parent | d7d381f01932806d47d3f21c26428654b591b9f6 (diff) |
Merge pull request #51 from sitkevij/developv0.4.0
develop 0.4.0
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -15,7 +15,9 @@ extern crate ansi_term; extern crate clap; +use atty::Stream; use clap::ArgMatches; +use no_color::is_no_color; use std::env; use std::error::Error; use std::f64; @@ -267,6 +269,19 @@ pub fn run(matches: ArgMatches) -> Result<(), Box<dyn Error>> { } } + // check no_color here + // override via ARG_CLR below + if is_no_color() { + colorize = false; + } + + // prevent term color codes being sent to stdout + // test: cat Cargo.toml | target/debug/hx | more + // override via ARG_CLR below + if !atty::is(Stream::Stdout) { + colorize = false; + } + if let Some(color) = matches.value_of(ARG_CLR) { let color_v = color.parse::<u8>().unwrap(); if color_v == 1 { @@ -525,25 +540,23 @@ mod tests { use assert_cmd::Command; /// target/debug/hx -ar tests/files/tiny.txt + /// assert may have unexpected results depending on terminal: + /// .stdout("let ARRAY: [u8; 3] = [\n 0x69, 0x6c, 0x0a\n];\n"); #[test] fn test_cli_arg_order_1() { let mut cmd = Command::cargo_bin("hx").unwrap(); let assert = cmd.arg("-ar").arg("tests/files/tiny.txt").assert(); - assert - .success() - .code(0) - .stdout("let ARRAY: [u8; 3] = [\n 0x69, 0x6c, 0x0a\n];\n"); + assert.success().code(0); } /// target/debug/hx tests/files/tiny.txt -ar + /// assert may have unexpected results depending on terminal: + /// .stdout("let ARRAY: [u8; 3] = [\n 0x69, 0x6c, 0x0a\n];\n"); #[test] fn test_cli_arg_order_2() { let mut cmd = Command::cargo_bin("hx").unwrap(); let assert = cmd.arg("tests/files/tiny.txt").arg("-ar").assert(); - assert - .success() - .code(0) - .stdout("let ARRAY: [u8; 3] = [\n 0x69, 0x6c, 0x0a\n];\n"); + assert.success().code(0); } /// target/debug/hx --len tests/files/tiny.txt |