diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe75c2d..cd31572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: include: - build: pinned os: ubuntu-18.04 - rust: 1.52.1 + rust: 1.56.1 - build: stable os: ubuntu-18.04 rust: stable @@ -74,7 +74,7 @@ jobs: # /target/arm-unknown-linux-gnueabihf/debug/rg target: arm-unknown-linux-gnueabihf - build: macos - os: macos-latest + os: macOS-11 rust: nightly - build: win-msvc os: windows-2019 @@ -92,7 +92,7 @@ jobs: ci/ubuntu-install-packages - name: Install packages (macOS) - if: matrix.os == 'macos-latest' + if: matrix.os == 'macOS-11' run: | ci/macos-install-packages @@ -116,6 +116,9 @@ jobs: echo "cargo command is: ${{ env.CARGO }}" echo "target flag is: ${{ env.TARGET_FLAGS }}" + - name: Update rustup for edition 2021 + run: rustup update stable + - name: Build tidy-viewer and all crates run: ${{ env.CARGO }} build --verbose --workspace ${{ env.TARGET_FLAGS }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 61ba450..9e97012 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -84,7 +84,7 @@ jobs: rust: nightly target: arm-unknown-linux-gnueabihf - build: macos - os: macos-latest + os: macOS-11 rust: nightly target: x86_64-apple-darwin - build: win-msvc @@ -112,7 +112,7 @@ jobs: ci/ubuntu-install-packages - name: Install packages (macOS) - if: matrix.os == 'macos-latest' + if: matrix.os == 'macOS-11' run: | ci/macos-install-packages diff --git a/CHANGELOG.md b/CHANGELOG.md index 3411aac..f3e28c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +1.4.3 (2021-11-17) +================== + +* **Feature 1** Added forced color flag for color pager support [Issue #112](https://github.com/alexhallam/tv/issues/112) + +I was not aware of this until @ismaelgv opened the issue. `less -R` and `bat -p` can do color comprehension. In previous versions of `tv` we just stripped the color if the output was piped to programs like less. Now the user can override this behaviour with a `-a` flag. + + 1.4.2 (2021-10-28) ================== diff --git a/Cargo.lock b/Cargo.lock index eef8062..6c4202b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -33,9 +33,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bstr" @@ -97,13 +97,13 @@ dependencies = [ [[package]] name = "console" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45" +checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" dependencies = [ "encode_unicode", - "lazy_static", "libc", + "once_cell", "regex", "terminal_size", "unicode-width", @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.20.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ebde6a9dd5e331cd6c6f48253254d117642c31653baa475e394657c59c1f7d" +checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c" dependencies = [ "bitflags", "crossterm_winapi", @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "crossterm_winapi" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a6966607622438301997d3dac0d2f6e9a90c68bb6bc1785ea98456ab93c0507" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" dependencies = [ "winapi", ] @@ -274,9 +274,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "mio" @@ -310,19 +310,16 @@ dependencies = [ ] [[package]] -name = "owo-colors" -version = "1.3.0" +name = "once_cell" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] -name = "pad" -version = "0.1.6" +name = "owo-colors" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ad9b889f1b12e0b9ee24db044b5129150d5eada288edc800f789928dc8c0e3" -dependencies = [ - "unicode-width", -] +checksum = "f9ad6d222cdc2351ccabb7af4f68bfaecd601b33c5f10d410ec89d2a273f6fff" [[package]] name = "parking_lot" @@ -412,9 +409,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.6" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", @@ -432,9 +429,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.23" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "ryu" @@ -566,7 +563,7 @@ dependencies = [ [[package]] name = "tidy-viewer" -version = "1.4.2" +version = "1.4.3" dependencies = [ "atty", "calm_io", @@ -577,7 +574,6 @@ dependencies = [ "itertools", "lazy_static", "owo-colors", - "pad", "regex", "serde", "structopt", diff --git a/Cargo.toml b/Cargo.toml index 25ed5b6..cde0495 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,13 +2,13 @@ authors = ["alexhallam "] categories = ["command-line-utilities"] description = "Head, but for csvs and with color" -edition = "2018" +edition = "2021" keywords = ["csv", "pretty-print", "data-viewer", "tv", "tabular-data-viewer"] license = "Unlicense/MIT" name = "tidy-viewer" readme = "README.md" repository = "https://github.com/alexhallam/tv" -version = "1.4.2" +version = "1.4.3" [package.metadata.deb] assets = [ @@ -28,15 +28,14 @@ section = "utility" [dependencies] atty = "0.2.14" calm_io = "0.1.1" -console = "0.14.1" -crossterm = "0.20.0" +console = "0.15.0" +crossterm = "0.22.1" csv = "1.1.6" directories = "4.0" itertools = "0.10.0" lazy_static = "1.4.0" -owo-colors = "1.3.0" -pad = "0.1" -regex = "1.4.5" +owo-colors = "3.0.1" +regex = "1.5.4" serde = {version = "1.0", features = ["derive"]} structopt = "0.3.21" toml = "0.5" diff --git a/README.md b/README.md index 3b3459b..898e600 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ ![example](img/starwars.png) # Contents +* [Featuers](#features) * [Installation](#installation) * [Examples](#examples) * [Significant Figure Definitions & Rules](#significant-figure-definitions-and-rules) @@ -21,6 +22,16 @@ * [Help](#help) * [Inspiration](#inspiration) +# Features + +1. Nice colors out of the box +2. Significant digit printing (no more decimal dust taking valuable terminal space) +3. NA comprehension and coloring (no more misaligned data cells due to missing data) +4. Dimensions printed first (no more guessing how many rows and columns are in the data) +5. Column overflow logic (no more misalignment do to terminal dimensions) +6. Long string/Unicode truncation (no more long strings pushing other data around) +7. Customizable with a dotfile config (bring your own theme) + # Installation The following install options are available @@ -295,7 +306,7 @@ For information on dotfile configuration see `tv --help`. This allows users to s `tv --help` ```txt -tv 1.4.2 +tv 1.4.3 Tidy Viewer (tv) is a csv pretty printer that uses column styling to maximize viewer enjoyment.✨✨📺✨✨ Example Usage: @@ -335,12 +346,14 @@ Tidy Viewer (tv) is a csv pretty printer that uses column styling to maximize vi #neg_num_color = [226, 125, 95] USAGE: - tv [FLAGS] [OPTIONS] [FILE] + tidy-viewer [FLAGS] [OPTIONS] [FILE] FLAGS: - -d, --debug-mode Print object details to make it easier for the maintainer to find and resolve bugs. - -h, --help Prints help information - -V, --version Prints version information + -d, --debug-mode Print object details to make it easier for the maintainer to find and resolve bugs. + -a, --color-always Always force color output. Example `tv -a starwars.csv | less -R` or `tv -a starwars.csv | bat + -p`. The `less` cli has the `-R` flag to parse colored output. + -h, --help Prints help information + -V, --version Prints version information OPTIONS: -c, --color @@ -359,6 +372,7 @@ OPTIONS: The lower (minimum) width of columns. Must be 2 or larger. [default: 2] -n, --number of rows to output Show how many rows to display. [default: 25] + -g, --sigfig Significant Digits. Default 3. Max is 7 [default: 3] -t, --title Add a title to your tv. Example 'Test Data' [default: NA] -u, --upper-column-width <upper-column-width> The upper (maxiumum) width of columns. [default: 20] diff --git a/src/main.rs b/src/main.rs index 7dec8c0..243008b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,12 @@ struct Cli { help = "Print object details to make it easier for the maintainer to find and resolve bugs." )] debug_mode: bool, + #[structopt( + short = "a", + long = "color-always", + help = "Always force color output. Example `tv -a starwars.csv | less -R` or `tv -a starwars.csv | bat -p`. The `less` cli has the `-R` flag to parse colored output." + )] + force_color: bool, #[structopt(name = "FILE", parse(from_os_str), help = "File to process")] file: Option<PathBuf>, @@ -171,6 +177,7 @@ fn main() { let is_footer_defined = opt.title.chars().count() > 0; let is_row_display_defined = !(opt.row_display == 25); let is_tty = atty::is(atty::Stream::Stdout); + let is_force_color = opt.force_color; let title_option = match (&config, is_title_defined) { (Some(x), false) => &x.title, @@ -406,7 +413,7 @@ fn main() { _ => Err(e), }, }; - if is_tty { + if is_tty || is_force_color { let _ = match stdoutln!( "{} {} {} {}", meta_text.truecolor(meta_color[0], meta_color[1], meta_color[2]), @@ -438,7 +445,7 @@ fn main() { _ => Err(e), }, }; - if is_tty { + if is_tty || is_force_color { let _ = match stdoutln!( "{}", title_option @@ -474,7 +481,7 @@ fn main() { //for col in 0..cols { for col in 0..num_cols_to_print { let text = vp[0].get(col).unwrap().to_string(); - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( "{}", text.truecolor(header_color[0], header_color[1], header_color[2]) @@ -518,7 +525,7 @@ fn main() { .take(rows) .skip(1) .for_each(|(i, row)| { - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( "{: <6}", i.truecolor(meta_color[0], meta_color[1], meta_color[2]) @@ -538,9 +545,8 @@ fn main() { }, }; } - //for col in 0..cols { row.iter().take(num_cols_to_print).for_each(|col| { - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( "{}", if datatype::is_na_string_padded(col) { @@ -579,7 +585,6 @@ fn main() { }); // additional row info - if rows_remaining > 0 { let _ = match stdout!("{: <6}", "") { Ok(_) => Ok(()), @@ -588,7 +593,7 @@ fn main() { _ => Err(e), }, }; - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( "{}", row_remaining_text.truecolor(meta_color[0], meta_color[1], meta_color[2]) @@ -608,7 +613,6 @@ fn main() { }, }; } - //println!("num_cols_to_print {:?} cols {:?}", num_cols_to_print, cols); let extra_cols_to_mention = num_cols_to_print; let remainder_cols = cols - extra_cols_to_mention; if extra_cols_to_mention < cols { @@ -616,7 +620,7 @@ fn main() { let meta_text_var = "more variables"; let meta_text_comma = ","; let meta_text_colon = ":"; - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( " {} {} {}{}", meta_text_and.truecolor(meta_color[0], meta_color[1], meta_color[2]), @@ -647,7 +651,7 @@ fn main() { } for col in extra_cols_to_mention..cols { let text = rdr[0].get(col).unwrap(); - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( " {}", text.truecolor(meta_color[0], meta_color[1], meta_color[2]) @@ -670,7 +674,7 @@ fn main() { // The last column mentioned in foot should not be followed by a comma if col + 1 < cols { - if is_tty { + if is_tty || is_force_color { let _ = match stdout!( "{}", meta_text_comma.truecolor(meta_color[0], meta_color[1], meta_color[2]) @@ -704,7 +708,7 @@ fn main() { _ => Err(e), }, }; - if is_tty { + if is_tty || is_force_color { let _ = match stdoutln!( "{}", footer_option.truecolor(meta_color[0], meta_color[1], meta_color[2])