Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag for all rows #158

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "Unlicense/MIT"
name = "tidy-viewer"
readme = "README.md"
repository = "https://github.com/alexhallam/tv"
version = "1.4.30"
version = "1.4.31"

[package.metadata.deb]
assets = [
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ For information on dotfile configuration see `tv --help`. This allows users to s
`tv --help`

```txt
tv 1.4.30
tv 1.4.31
Tidy Viewer (tv) is a csv pretty printer that uses column styling to maximize viewer enjoyment.✨✨📺✨✨

Example Usage:
Expand Down Expand Up @@ -375,6 +375,8 @@ USAGE:
FLAGS:
-d, --debug-mode Print object details to make it easier for the maintainer to find and resolve bugs.
-e, --extend-width-and-length Extended width beyond term width (do not truncate). Useful with `less -S`.
-f, --force-all-rows Print all rows in file. May be piped to 'less -S'. Example `tidy-viewer
data/diamonds.csv -f -a | less -R`
-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
Expand All @@ -391,7 +393,7 @@ OPTIONS:
(4)dracula
(5)solarized light [default: 0]
-s, --delimiter <delimiter> The delimiter separating the columns.
-f, --footer <footer> Add a footer to your tv. Example 'footer info' [default: NA]
-F, --footer <footer> Add a footer to your tv. Example 'footer info' [default: NA]
-l, --lower-column-width <lower-column-width>
The lower (minimum) width of columns. Must be 2 or larger. [default: 2]

Expand Down Expand Up @@ -445,6 +447,14 @@ cd testdata
ls -l --block-size=M # the data is fairly large at 192MB
```

## Fun With `tv`

Using `duckdb` with `tv` and `less` to manipulate data with SQL grammar and view results in a scrolling window.

```sh
duckdb --csv -c "select norm1 from norms.csv" | ../target/release/tidy-viewer -f -a | less -R
```

### DuckDB One-liner
```bash
duckdb --csv -c "SELECT passenger_count, COUNT(*), AVG(total_amount) FROM taxi.csv GROUP BY passenger_count ORDER BY passenger_count" | tv
Expand Down
Empty file added data/empty.csv
Empty file.
101 changes: 101 additions & 0 deletions data/flag_f_test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
norm1,norm2
0.13985051995067665,1.6383104658547452
1.421378935825573,-0.8839007298586234
0.1785258179751344,0.31826458774367516
0.1799228728368547,-0.6988502656285692
-0.3601770130525013,-0.020698820812483455
1.8513345120712446,2.2725994983955653
-1.0265053128729604,0.05902414053358411
1.1303482682646326,-0.17814104299104694
0.3757364188183757,0.5149242774993619
-0.18402628567217905,-0.42757719811846356
1.4289001286164538,0.3015858107744048
1.2662178084324671,0.31026257648975886
-1.5551459999848616,0.4524037605104499
-0.08176843684626088,-0.8040629766462795
-1.253797781969998,1.08385590171137
0.13521771358169038,-0.26862223305766886
0.45934792507298405,1.3145432113792468
1.4218768209890322,-0.9384012274373347
-1.8053819464500829,-0.9508906475992313
0.14685455231223585,-0.5703522396392591
-1.6059052140400474,-0.30634472340875124
-0.7531078472058763,-1.035141243731728
1.5402633909248478,0.5957337537671182
0.3425162134540953,0.2603703440308933
-1.1338832231790217,-0.7721415171054437
0.7680488518188675,0.20718511495874553
0.7707182008280404,-0.5934674993125825
0.21419017294796816,-0.1215079240941617
0.11186073081091127,-0.7020972548553469
0.7042713299033002,0.4763183906616271
0.07309669153428934,-2.1703849268671673
-2.277812709325943,-0.44821836027018963
-0.7600438986427108,1.654344927131341
-0.14008262537120889,-0.05136057426238785
0.15503065800645952,-0.2648767505230992
-1.0774036075513131,0.3698728636281447
-0.9635506973470577,-1.3543641278454903
-0.6322033504220768,-2.092409283763339
0.5761553197212829,-1.745405096551917
-0.6707433349502127,-0.9392379193738705
0.1507992518225445,0.8578014684226983
-0.3259145435764771,0.09649587834065654
-2.1933592202760708,1.6656093910137608
-0.7835803318024548,0.7733900181117273
-0.09308419890671939,0.5598531674117911
0.3962375814797756,-2.3530645318259307
0.195814796447321,1.3070516907556993
-0.22581072667455898,-0.24327613511932486
-1.624985713077208,-0.045702945815789965
-2.499242489625264,0.47190665039719304
-0.22452018245808683,0.6139164247910265
-0.20191678733639112,-1.5732138879617978
0.5211497557996678,-0.13568812432143282
0.37925040344277294,-0.9357461883587928
0.36580251139578734,0.33209422570093183
-0.23443318147414494,0.10274744436067688
-1.2229637904228463,1.326276360042395
1.576748801464897,1.6788586310258746
2.000292597472959,-0.04156001113713152
2.015588611581564,0.47039415705163595
0.12980096695632687,0.738549439485428
-1.754683993317322,0.22420537546681568
0.8482604883670286,-2.1054726389644083
1.3195659263685986,0.7467259629278016
-0.996331165514739,0.15512834953939594
0.6786266052226674,-0.1593598185485379
-1.8758975967520295,-0.5609980044362779
-1.4760949427844057,0.8596552929485344
0.7688552622650165,-0.14125669085755704
2.5526194759272154,-0.5441164673298301
0.40907684601598865,-1.3680415392537844
-0.9551936453512807,0.5704631213481213
-0.7394967774201214,-0.4267799676289153
0.40113968550325096,0.895160370240519
-0.6204597458914537,0.7148183592024948
0.7772767490666314,-0.664935090926009
0.03543232661595703,1.834222745657818
0.8327929698133663,0.5695884233794615
0.29166662863122916,-0.8008446085025178
0.45452903360475394,1.9903035590190936
2.637558907533413,-0.16674383672500806
-1.3979934325880123,0.48175710504022484
0.39420843930945343,-3.3112963265699626
-1.360417178738406,0.5355947996833801
-0.7931652471643392,-1.6333262060782503
1.6950465249363347,-0.6774802608261188
-0.16765820356313227,-0.07929041071217462
-0.7589371503848853,-1.1523384417103064
-0.04461572285634458,-0.6370571134752231
-0.5849625114774933,-0.27179711623879005
2.1122285399796517,-1.3590952935055733
-0.7722728522993133,0.7669466360666433
0.3692781810640897,-0.3433717555299436
1.4894342375264467,0.6620692124839108
-0.10192638359178102,-0.02756159292605862
-0.2487262933440482,0.4842822485082466
-2.4282497794372033,0.40581185404407366
-0.8509956030993339,1.1516589942485569
0.4169675151536681,0.15630241150963292
1.052776698227522,1.7112688099363234
66 changes: 64 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ struct Cli {
(5)solarized light"
)]
color: usize,
#[structopt(
short = "f",
long = "force-all-rows",
help = "Print all rows in file. May be piped to 'less -S'. Example `tidy-viewer data/diamonds.csv -f -a | less -R`"
)]
force_all_rows: bool,
#[structopt(
short = "t",
long = "title",
Expand All @@ -79,7 +85,7 @@ struct Cli {
)]
title: String,
#[structopt(
short = "f",
short = "F",
long = "footer",
default_value = "NA",
help = "Add a footer to your tv. Example 'footer info'"
Expand Down Expand Up @@ -204,6 +210,7 @@ fn main() {
let is_force_color: bool = opt.force_color;
let is_no_dimensions: bool = opt.no_dimensions;
let is_no_row_numbering: bool = opt.no_row_numbering;
let is_force_all_rows: bool = opt.force_all_rows;

let extend_width_length_option: bool = opt.extend_width_length
|| config
Expand Down Expand Up @@ -409,7 +416,17 @@ fn main() {
rdr.len().min(row_display_option + 1)
};

let rows_remaining: usize = rows_in_file - rows;
//let rows_remaining: usize = rows_in_file - rows;
let rows_remaining: usize = match is_force_all_rows {
true => 0,
false => rows_in_file - rows,
};

let rows = match is_force_all_rows {
true => rows_in_file,
false => rows,
};

let ellipsis = '\u{2026}'.to_string();
let row_remaining_text: String = format!("{} with {} more rows", ellipsis, rows_remaining);

Expand Down Expand Up @@ -1184,4 +1201,49 @@ mod tests {
assert_eq!(datatype::is_negative_number("text"), false);
assert_eq!(datatype::is_negative_number("-123.123.123"), false);
}

#[test]
fn test_flag_f() {
// don't have a convenient way to push data through tv
// just want to make sure that all rows of data are printed
// as opposed to the default 25
let _v: Vec<Vec<&str>> = vec![
vec!["norm1"],
vec!["0.13985051995067665"],
vec!["1.421378935825573"],
vec!["0.1785258179751344"],
vec!["0.1799228728368547"],
vec!["-0.3601770130525013"],
vec!["1.8513345120712446"],
vec!["-1.0265053128729604"],
vec!["1.1303482682646326"],
vec!["0.3757364188183757"],
vec!["-0.18402628567217905"],
vec!["1.4289001286164538"],
vec!["1.2662178084324671"],
vec!["-1.5551459999848616"],
vec!["-0.08176843684626088"],
vec!["-1.253797781969998"],
vec!["0.13521771358169038"],
vec!["0.45934792507298405"],
vec!["1.4218768209890322"],
vec!["-1.8053819464500829"],
vec!["0.14685455231223585"],
vec!["-1.6059052140400474"],
vec!["-0.7531078472058763"],
vec!["1.5402633909248478"],
vec!["0.3425162134540953"],
vec!["-1.1338832231790217"],
vec!["0.7680488518188675"],
vec!["0.7707182008280404"],
vec!["0.21419017294796816"],
vec!["0.11186073081091127"],
vec!["0.7042713299033002"],
vec!["0.07309669153428934"],
vec!["-2.277812709325943"],
vec!["-0.7600438986427108"],
vec!["-0.14008262537120889"],
vec!["0.15503065800645952"],
];
}
}