Skip to content

Commit

Permalink
Adds new extend-rows flag (-e) to disable truncation (#116)
Browse files Browse the repository at this point in the history
Adds a new extend-rows flag (-e) which allows the user to disable row
truncation. This is super helpful for wide csv files that are larger
than the terminal width. When using this flag, pipe output to `less -S`
to be able to use the arrow keys to scroll right and left to actually
view the overflowing columns.

Eg:

    `tidy-viewer -e wide.csv | less -S`

Or even... to preserve colors through less...

    `tidy-viewer -a -e wide.csv | less -S`.
  • Loading branch information
5tefan authored Nov 20, 2021
1 parent 3b5bd3f commit 377de4e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.4.4 (2021-11-18)
==================

* **Feature 1** Added -e flag to extend rows (don't truncate).

This new version gives a flag option to extend rows rather than truncate. This is especially useful for wide csv files that would overflow the terminal width. When using the extend mode, pipe output to `less -S` to enables scrolling right and left with arrow keys.

1.4.3 (2021-11-17)
==================

Expand Down
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.3"
version = "1.4.4"

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

```txt
tv 1.4.3
tv 1.4.4
Tidy Viewer (tv) is a csv pretty printer that uses column styling to maximize viewer enjoyment.✨✨📺✨✨
Example Usage:
Expand Down Expand Up @@ -338,6 +338,8 @@ 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"
#meta_color = [64, 179, 162]
## header_color = [R,G,B] color for column headers
Expand All @@ -354,6 +356,7 @@ USAGE:
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
Expand Down
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use toml;
#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\"
#meta_color = [64, 179, 162]
## header_color = [R,G,B] color for column headers
Expand Down Expand Up @@ -117,6 +119,12 @@ struct Cli {
help = "Significant Digits. Default 3. Max is 7"
)]
sigfig: i64,
#[structopt(
short = "e",
long = "extend-rows",
help = "Extended row beyond term width (do not truncate). Useful with `less -S`."
)]
extend: bool,
#[structopt(
short = "d",
long = "debug-mode",
Expand Down Expand Up @@ -144,6 +152,7 @@ fn main() {
upper_column_width: usize,
lower_column_width: usize,
number: usize,
extend_rows: bool,
meta_color: toml::value::Array,
header_color: toml::value::Array,
std_color: toml::value::Array,
Expand All @@ -157,12 +166,12 @@ fn main() {
let conf_file = PathBuf::from("tv.toml");
let conf_dir_file: PathBuf = config_dir.join(conf_file.clone());
let file_contents: Option<String> = std::fs::read_to_string(conf_dir_file).ok();
//println!("file_contents {:?}", file_contents);
// println!("file_contents {:?}", file_contents);
let config: Option<Data> = match file_contents {
Some(x) => toml::from_str(&x.to_owned()).ok(),
None => None,
};
//println!("config {:#?}", config);
// println!("config {:#?}", config);

let term_tuple = size().unwrap();
let opt = Cli::from_args();
Expand All @@ -178,6 +187,7 @@ fn main() {
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 extend_option = opt.extend || config.as_ref().map(|d| d.extend_rows).unwrap_or(false);

let title_option = match (&config, is_title_defined) {
(Some(x), false) => &x.title,
Expand Down Expand Up @@ -401,7 +411,11 @@ fn main() {
vp.push(row);
}

let num_cols_to_print = get_num_cols_to_print(cols, vp.clone(), term_tuple);
let num_cols_to_print = if extend_option {
cols
} else {
get_num_cols_to_print(cols, vp.clone(), term_tuple)
};

// color
let meta_text = "tv dim:";
Expand Down

0 comments on commit 377de4e

Please sign in to comment.