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

Clippy fix #143

Merged
merged 9 commits into from
Jul 23, 2022
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
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cSpell.words": [
"abcdefghijkl",
"abcdefghijklmnop",
"atsalolikhin",
"briandconnelly",
"colname",
"crossterm",
"floatlike",
"FOLDERID",
"gruv",
"gruvbox",
"spokeo",
"stdoutln",
"structopt",
"truecolor"
]
}
37 changes: 30 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
1.4.6 (2022-7-23)
==================

This update was mainly focused on feature enhancements. I also did some `clippy` formatting.

* **Bug** [#141](https://github.com/alexhallam/tv/issues/141) Right alignment of row numbers might make it easier for users to quickly scan the output.

I did not realize that I had the alignment wrong. I was doing left alignment, but it was brought to my attention that `tibble` uses right alignment.
This is now corrected. Thanks for the sharp eye @briandconnelly.

* **Bug** [#140](https://github.com/alexhallam/tv/issues/140) `-n` option doesn't work when combined with `--extend-rows`

This was a bug I was not aware of that I wanted to knock out. Thanks @atsalolikhin-spokeo for using this package and reporting the issue. Your
report made the cli a little better.

* **Enhancement, Good first issue** [#139](https://github.com/alexhallam/tv/issues/139) Is it possible to turn off row numbering?

As requested I implemented `-R`, `--no-row-numbering` for this functionality

* **Enhancement, Good first issue** [#138](https://github.com/alexhallam/tv/issues/138) Is it possible to turn off dimensions printing?

As requested I implemented `-D`, `--no-dimensions` for this functionality

1.4.5 (2021-5-1)
==================

Expand All @@ -20,7 +43,7 @@ I also did some clean up work. I removed a binary I was not using.

* **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.
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 behavior with a `-a` flag.


1.4.2 (2021-10-28)
Expand Down Expand Up @@ -78,7 +101,7 @@ We also saw some code quality improvements in this release. [PR #82](https://git

The version number jump was due to testing out github actions on automated releases using git tags as the release name. It took a few tries to get right.

* **Feature 1** Add package to snapcraft to increase accessibility.
* **Feature 1** Add package to `snapcraft` to increase accessibility.
* [bug #55](https://github.com/alexhallam/tv/issues/55):
fix panic on unicode string truncation
* [BUG #40](https://github.com/alexhallam/tv/issues/30):
Expand All @@ -96,18 +119,18 @@ This version was made possible by the contributions of @Lireer! Thank You!

* [PR #40](https://github.com/alexhallam/tv/pull/40) Allow users to specify the deliminator with the `delimiter` option.
* [PR #42](https://github.com/alexhallam/tv/pull/42) `clippy` warnings and code refactoring.
* [PR #41](https://github.com/alexhallam/tv/pull/41) change `.len()` to `.chars().count()` to avoid potential column widths if the calue contains code points consisting of multiple bytes.
* [PR #41](https://github.com/alexhallam/tv/pull/41) change `.len()` to `.chars().count()` to avoid potential column widths if the value contains code points consisting of multiple bytes.

0.0.12 (2021-09-09)
==================
* [BUG #33](https://github.com/alexhallam/tv/issues/33) Elipses used when NA should replace on unquoted string missingness #33
* [BUG #33](https://github.com/alexhallam/tv/issues/33) Ellipses used when NA should replace on unquoted string missingness #33
This problem was caused by all of the columns being width 1. When width is 1 the length of the string "NA" is 2. Since 2 was greater
than 1 NA was converted to elipses. To fix this problem I added a min width of 2 and while I was at it I includeed a new option `lower-column-width`
than 1 NA was converted to ellipses. To fix this problem I added a min width of 2 and while I was at it I included a new option `lower-column-width`
* [BUG #32](https://github.com/alexhallam/tv/issues/32) Column with integer 1 and 0 returns NaN for 0.
This bug was caused by logging 0s. I added a condition on the sigfig decision tree to fix.
* **Feature 1** `lower-column-width`: `The lower (minimum) width of columns. Must be 2 or larger. Default 2. `
* **Feature 2** `upper-column-width`: `The upper (maxiumum) width of columns. Default 20.`
* **Feature 2** `debug-mode`: `Print object details to make it easier for the maintainer to find and resolve bugs.` This is to save me time in the futre :smile:
* **Feature 2** `upper-column-width`: `The upper (maximum) width of columns. Default 20.`
* **Feature 2** `debug-mode`: `Print object details to make it easier for the maintainer to find and resolve bugs.` This is to save me time in the future :smile:

0.0.10 (2021-08-05)
==================
Expand Down
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.

28 changes: 23 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@ authors = ["alexhallam <[email protected]>"]
categories = ["command-line-utilities"]
description = "Head, but for CSV files and with color"
edition = "2021"
keywords = ["csv", "pretty-print", "data-viewer", "tv", "tabular-data-viewer", "csv-viewer", "csv-pretty-print", "csv-cat", "csv-column"]
keywords = [
"csv",
"pretty-print",
"data-viewer",
"tv",
"tabular-data-viewer",
"csv-viewer",
"csv-pretty-print",
"csv-cat",
"csv-column",
]
license = "Unlicense/MIT"
name = "tidy-viewer"
readme = "README.md"
repository = "https://github.com/alexhallam/tv"
version = "1.4.5"
version = "1.4.6"

[package.metadata.deb]
assets = [
["target/release/tidy-viewer", "usr/bin/", "755"],
["README.md", "usr/share/doc/cargo-deb/README", "644"],
[
"target/release/tidy-viewer",
"usr/bin/",
"755",
],
[
"README.md",
"usr/share/doc/cargo-deb/README",
"644",
],
]
depends = "$auto"
extended-description = """\
Expand All @@ -36,7 +54,7 @@ itertools = "0.10.0"
lazy_static = "1.4.0"
owo-colors = "3.0.1"
regex = "1.5.4"
serde = {version = "1.0", features = ["derive"]}
serde = { version = "1.0", features = ["derive"] }
structopt = "0.3.21"
toml = "0.5"
unicode-truncate = "0.2.0"
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ cat diamonds.csv | tv
```sh
wget https://raw.githubusercontent.com/tidyverse/dplyr/master/data-raw/starwars.csv

# Pass as agrument
# Pass as argument
tv starwars.csv
```

Expand Down Expand Up @@ -148,10 +148,10 @@ tv titanic.csv -a -n 1000 | bat -p
Choosing the sigfigs amounts to how much of the value of a number is desired. The table below shows an example calculation with variable sigfigs.

| sigfigs | value | sigfiged_value | %value_of_the_number_explained_by_sigfiged_vale |
|---------|--------|----------------|:-----------------------------------------------:|
| 1 | 0.1119 | 0.1 | >89% |
| 2 | 0.1119 | 0.11 | >98% |
| 3 | 0.1119 | 0.111 | >99% |
| ------- | ------ | -------------- | :---------------------------------------------: |
| 1 | 0.1119 | 0.1 | >89% |
| 2 | 0.1119 | 0.11 | >98% |
| 3 | 0.1119 | 0.111 | >99% |

`tv` uses the same significant figure (sigfig) rules that the R package `pillar` uses.

Expand Down Expand Up @@ -226,7 +226,7 @@ There are only 4 outputs possible. The significant figures to display are set by


```text
# Psuedo Code: Sigfig logic assuming sigfig = 3
# Pseudo Code: Sigfig logic assuming sigfig = 3
if lhs == 0:
n = ((floor(log10(abs(x))) + 1 - sigfig)
r =(10^n) * round(x / (10^n))
Expand Down Expand Up @@ -308,12 +308,13 @@ For information on dotfile configuration see `tv --help`. This allows users to s
`tv --help`

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

Example Usage:
wget https://raw.githubusercontent.com/tidyverse/ggplot2/master/data-raw/diamonds.csv
cat diamonds.csv | head -n 35 | tv
tv diamonds.csv

Configuration File Support:
An example config is printed to make it easy to copy/paste to `tv.toml`.
Expand All @@ -337,9 +338,10 @@ Tidy Viewer (tv) is a csv pretty printer that uses column styling to maximize vi
#lower_column_width = 2
## head number of rows to output <row-display> [default: 25]
#number = 35
## extend rows beyond term width (do not trucate) [default: false]
# extend_rows = true
## meta_color = [R,G,B] color for row index and "tv dim: rowsxcols"
## extend width and length in terms of the number of rows and columns displayed beyond term width [default:
false]
# extend_width_and_length = true
## meta_color = [R,G,B] color for row index and "tv dim: rows x cols"
#meta_color = [64, 179, 162]
## header_color = [R,G,B] color for column headers
#header_color = [232, 168, 124]
Expand All @@ -354,12 +356,14 @@ USAGE:
tidy-viewer [FLAGS] [OPTIONS] [FILE]

FLAGS:
-d, --debug-mode Print object details to make it easier for the maintainer to find and resolve bugs.
-e, --extend-rows Extended row beyond term width (do not truncate). Useful with `less -S`.
-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
-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`.
-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
-D, --no-dimensions Turns off dimensions of the data
-R, --no-row-numbering Turns off row numbering
-V, --version Prints version information

OPTIONS:
-c, --color <color>
Expand All @@ -368,7 +372,7 @@ OPTIONS:
(2)one_dark
(3)gruvbox
(4)dracula
(5)solarized light
(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]
-l, --lower-column-width <lower-column-width>
Expand All @@ -377,7 +381,7 @@ OPTIONS:
-n, --number of rows to output <row-display> Show how many rows to display. [default: 25]
-g, --sigfig <sigfig> Significant Digits. Default 3. Max is 7 [default: 3]
-t, --title <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]
-u, --upper-column-width <upper-column-width> The upper (maximum) width of columns. [default: 20]

ARGS:
<FILE> File to process
Expand All @@ -389,7 +393,7 @@ Here I show how to use `tv` with a couple of database engines (SQLite, DuckDB).

## Use With SQLite

[Sqlite](https://www.sqlite.org/index.html) is a fantistic program! If it is not the most deployed software it is probably close to it. For more info on SQLite see their [Executive Summary](https://www.sqlite.org/about.html)
[Sqlite](https://www.sqlite.org/index.html) is a fantastic program! If it is not the most deployed software it is probably close to it. For more info on SQLite see their [Executive Summary](https://www.sqlite.org/about.html)

For this example you will need to download and uncompress taxi data

Expand All @@ -415,7 +419,7 @@ For this example you will need to download and uncompress taxi data
wget https://github.com/multiprocessio/dsq/blob/43e72ff1d2c871082fed0ae401dd59e2ff9f6cfe/testdata/taxi.csv.7z?raw=true -O taxi.csv.7z
7z x taxi.csv.7z
cd testdata
ls -l --block-size=M # the data is farily large at 192MB
ls -l --block-size=M # the data is fairly large at 192MB
```

### DuckDB One-liner
Expand Down
2 changes: 1 addition & 1 deletion src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn format_strings(
.map(|(string, len)| {
if len > max_width {
let (rv, _) = string.unicode_truncate(max_width - 1);
let spacer: &str = &" ";
let spacer: &str = " ";
let string_and_ellipses = [rv.to_string(), ellipsis.to_string()].join("");
[string_and_ellipses, spacer.to_string()].join("")
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/datatype/sigfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn get_final_string(x: f64, lhs: f64, rhs: f64, neg: bool, sigfig: i64) -> S
//let total_string = total.to_string();
let w: usize = (sigfig as usize) - 1;
let x = format!("{:.w$}", x, w = w);
let total_string = x.to_string();
let total_string = x;
let total_clone = total_string.clone();
let split = total_clone.split('.');
let vec: Vec<&str> = split.collect();
Expand All @@ -234,7 +234,7 @@ pub fn get_final_string(x: f64, lhs: f64, rhs: f64, neg: bool, sigfig: i64) -> S
//let total_string = total.to_string();
let w: usize = (sigfig as usize) - 1;
let x = format!("{:.w$}", x, w = w);
let total_string = x.to_string();
let total_string = x;
let total_clone = total_string.clone();
let split = total_clone.split('.');
let vec: Vec<&str> = split.collect();
Expand Down
Loading