News for hackers. Stuff that matters.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @09:15AM (#28670253)
I spend a lot of time in the terminal and want to quickly glance at a csv files without making a new script, opening excel, or using a tui. I made tidy-viewer (tv) because current tools like cat and column were not pretty enough.

tv modifies raw files in the following ways:

1. NA detection and highlighting 2. Printing only significant digits 3. Header and footer meta data

I have been using this a lot at work. There is a lot more work to do, but it is in a usable state.

Give it a try! If you like it then star on Github!

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by contravariant on Monday September 27, 2021 @11:15AM (#28671683)
The NA detection and higlighting is nice but I'm not sure how I feel about showing anything other than the exact textual value. I don't mind abridging quotes when they're not necessary, but showing "N/A", NA,, etc. as the same value is a bit iffy.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by psadauskas on Monday September 27, 2021 @12:00PM (#28672368)
When presented with a similar problem, I tend to use non-ascii characters. For example, in my `~/.psqlrc` I have:

    \pset null ␀
Looks like this in output:

    40 |       ␀ | 2021-09-23 20:42:32.536571 | ␀
    41 |      15 | 2021-09-23 20:42:33.177474 | ␀
    42 |      19 | 2021-09-23 20:42:33.212133 | ␀
    43 |       ␀ | 2021-09-23 20:42:33.247346 | ␀
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by a1369209993 on Monday September 27, 2021 @02:43PM (#28674395)
I was going compain about null bytes in text (never, period), but then realized you actually did mean the U+2400 SYMBOL FOR NULL[0] character itself. That's surprisingly viable (though you do now have to worry about the string "\xE2\x90\x80" ending up in your data).

0: Which is actually incorrectly named - it should be "SYMBOL FOR NUL".

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @11:33AM (#28671931)
It is rough. There are many ways that different tools put NAs, na, N/A, "", etc. in a file. To chose only "NA" would mean I would be excluding the output of other tools. I chose accessibility over specificity. #trade-offs.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by contravariant on Monday September 27, 2021 @12:47PM (#28673010)
Fair enough but that doesn't explain why you chose to display all of them as "NA". As you say there are lots of different ones, hence it would be a bad idea to pick one as the 'default' to display. To me it's important whether something is missing, filled with "N/A", or "null", or "Not Applicable" etc.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by eevilspock on Monday September 27, 2021 @01:45PM (#28673765)
Simple: provide CLI switches to let the user decide what they want for NA detection (current behavior as default, user can provide alternate NA values, per the source file or the natural language it is expressed in), and how they want them displayed, whether as-is, blank or a consistent custom value (as-is should be the default).
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by ayoubElk on Monday September 27, 2021 @11:43AM (#28672092)
Maybe you could just background highlight the empty cells?
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @12:01PM (#28672388)
Well, I think being promiscuous with "NA", "N/A", nan, etc. is a separate issue from a blank cell. A blank cell is literally missing. That should be filled with NA.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by nicoburns on Monday September 27, 2021 @12:24PM (#28672685)
> A blank cell is literally missing. That should be filled with NA.

Why? "NA" stands for "Not Applicable", but a blank cell in a CSV could represent any number of things of which "Not Applicable" is only one.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @12:41PM (#28672912)
haha. You are right "NA" stands for "Not Applicable". That is not always how people/programs using it though. What are some alternatives that you would suggest? I am happy to learn.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by nicoburns on Monday September 27, 2021 @12:44PM (#28672957)
I would suggest similar to what other people have suggested where you color the background of the cell red and then just display the literal content of the cell. I think it would be reasonable to have this configurable via command line arguments though, so if you like the "NA" that could also be a mode.

Perhaps it would make sense to have a "pretty" mode and a "literal" mode (which would also turn off the clever processing of numbers)?

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by ac29 on Tuesday September 28, 2021 @12:40AM (#28679415)
I prefer "ND" (No Data), personally.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by einpoklum on Monday September 27, 2021 @11:10AM (#28671591)
First of all - kudos on tackling this task - it is indeed very annoying to get CSVs to render nicely on a terminal.

1. How does tidy-viewer compare with csvlook?

2. Looking at the demo video, there seems to be an odd fixation with "N/A". The CSV spec, AFAIK, doesn't recognize this phrase. I don't understand why someone would expect a quoted string field whose raw characters are "n/a" should be rendered as anything other than n/a (i.e. lowercase and without the quotes). I'm guessing maybe in your workflow you want to use that phrase a lot, but for a tool for the general public I'd not do this kind of interpretation; and I would leave an empty field as empty.

3. tidy-viewer seems to require "unstable library features", or at least ones which were unstable as of Rust 1.48.0 . It would be nice if you could be compatible with older rust distributions/versions.

4. Many systems, especially older ones, especially ones which you access remotely and don't have root privileges on, won't have a rust installation. It would be even more convenient if you could provide binaries with little or no extra dynamic library dependencies, which could be used on older / rustless systems. I realize this is a tall order, however.

5. What about scrolling? The worst part of viewing CSVs is having to handle wide ones which exceed the terminal width, and having decent horizontal as well as vertical scrolling ability. less doesn't cut it, because it doesn't keep the header row, plus it doesn't recognize field widths.

6. tidy-viewer does not seem to support wrapping longer fields onto multiple terminal lines.

7. When the user doesn't specify the color scheme, are you choosing one based on the terminal colors, or are you using absolute color values? I suggest the former.

8. tidy-viewer loads and parses the entire CSV immediately; and, in fact, seems to keep two copies of it in memory at once. This means it cannot be used with large files without thrashing; and even if your CSV does fit in global memory, it will still be kind of unusable, trying to dump gigabytes onto the terminal.

Bottom line: A nice initial effort, but the more serious challenges are yet to be tackled, plus needs to be more robustly cross-platform.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by notafraudster on Monday September 27, 2021 @11:15AM (#28671678)
The norm of treating missing data as NA exists in R (which the developer of this is clearly inspired by based on the GitHub readme.). Pandas in Python is stuck with NaN for numeric types (not quite correct) and "" or None for string types. Personally I like the choice to both explicitly render missing data in colour and to apply NA as a placeholder text to display that colour.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by bofh23 on Thursday September 30, 2021 @06:10PM (#28711965)
> 5. What about scrolling?

The less(1) command has horizontal scrolling, just invoke it with the -S or --chop-long-lines options or toggle that feature while paging a file.

I agree it would be nicer if less(1) had a user configurable header with a format option to set it to the contents of the first line in a file or stdin or perhaps the most recent line matching a regex to allow for multiple tables and an option to make it scroll horizontally in -S or --chop-long-lines mode.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @12:35PM (#28672823)
First of all - kudos on tackling this task - it is indeed very annoying to get CSVs to render nicely on a terminal.

> How does tidy-viewer compare with csvlook?

The most important issue to me is that csvlook is a much less pleasant viewing experience, but there is also this ...csvlook reads and parses all of the data. Try pushing diamonds.csv to csvlook. When I do it on my machine it takes 15.228 seconds while tv takes 0.0042 seconds. For this reason tv is much faster, but speed is not the goal of the package. tv's purpose is to maximize viewer enjoyment.

2. Looking at the demo video, there seems to be an odd fixation with "N/A". The CSV spec, AFAIK, doesn't recognize this phrase. I don't understand why someone would expect a quoted string field whose raw characters are "n/a" should be rendered as anything other than n/a (i.e. lowercase and without the quotes). I'm guessing maybe in your workflow you want to use that phrase a lot, but for a tool for the general public I'd not do this kind of interpretation; and I would leave an empty field as empty.

I could not say it better than this:

> The norm of treating missing data as NA exists in R (which the developer of this is clearly inspired by based on the GitHub readme.). Pandas in Python is stuck with NaN for numeric types (not quite correct) and "" or None for string types. Personally I like the choice to both explicitly render missing data in colour and to apply NA as a placeholder text to display that colour.

3. tidy-viewer seems to require "unstable library features", or at least ones which were unstable as of Rust 1.48.0 . It would be nice if you could be compatible with older rust distributions/versions.

That is a good point. I also release binaries which I think makes this requirement less needed. What are your thoughts.

4. Many systems, especially older ones, especially ones which you access remotely and don't have root privileges on, won't have a rust installation. It would be even more convenient if you could provide binaries with little or no extra dynamic library dependencies, which could be used on older / rustless systems. I realize this is a tall order, however.

With github actions I auto-build binaries for many OSes. See https://github.com/alexhallam/tv/releases/tag/0.0.13

5. What about scrolling? The worst part of viewing CSVs is having to handle wide ones which exceed the terminal width, and having decent horizontal as well as vertical scrolling ability. less doesn't cut it, because it doesn't keep the header row, plus it doesn't recognize field widths.

Scrolling is nice. To offer scrolling the only option I am aware of is turning this cli into a tui. I made the choice early on to stay chose the more minimal path and stick to a cli. The goal is to be a `column` replacement not a spreadsheet replacement.

6. tidy-viewer does not seem to support wrapping longer fields onto multiple terminal lines.

The goal is to glance at the data as a whole not a cell or fields. If there are cells with long text they get cut at 20 characters. I like this a lot. I would prefer to know that there is a lot of text that I can dig into latter, but when I am glancing at the csv I just want an overall picture. In my view tables of data are data visualizations meaning that I don't have to show everything to understand enough of it.

7. When the user doesn't specify the color scheme, are you choosing one based on the terminal colors, or are you using absolute color values? I suggest the former.

Great question. I want to eventually add the ability for users to make a config file will their own colors. At this time I just have absolute presets. If you are interested I would happily take a contribution that allows users the option to configure tv with some dotfile.

8. tidy-viewer loads and parses the entire CSV immediately; and, in fact, seems to keep two copies of it in memory at once. This means it cannot be used with large files without thrashing; and even if your CSV does fit in global memory, it will still be kind of unusable, trying to dump gigabytes onto the terminal.

That is almost true. tidy-viewer reads the entire csv, but only parses the head. If I knew of a way to get the number of rows and columns of a csv without reading the whole file then I would. I know there is a good deal more room for memory optimization. This is not my strength and I am still learning.

9. Bottom line: A nice initial effort, but the more serious challenges are yet to be tackled, plus needs to be more robustly cross-platform.

Thanks for the compliment. It is still a work in progress.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by moritonal on Monday September 27, 2021 @10:41AM (#28671205)
Man.. TV is such a good name for a visualiser tool that it'd be excellent if it could pretty-print any content given to it.

Does your framework support the idea of pre-parsing the file's content and selecting an appropriate renderer, or is it fairly tied to CSVs?

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @11:34AM (#28671955)
I would need more details on what you mean by "pre-parsing". It works with any deliminator, it could be comma-separated, pipe-separated, etc.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by mixmastamyk on Monday September 27, 2021 @12:06PM (#28672465)
Doesn't need to be pre-parsed. Perhaps give the filename to the utility instead of content via stdin. Then filename gives a hint. If there is none, run "file filename" (via library) beforehand.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by inostia on Monday September 27, 2021 @01:29PM (#28673577)
I actually like `tidy` better and honestly would rather have `cat a.csv | tidy ...`. But it's probably already a thing.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Thursday September 30, 2021 @12:14PM (#28708035)
You don't have to make the alias `tv`. Feel free to make your alias tidy='tidy-viewer'.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by hnlmorg on Monday September 27, 2021 @06:14PM (#28676694)
Nice idea. I might actually work on this myself
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by asicsp on Monday September 27, 2021 @11:34AM (#28671962)
Hey, if you are able to edit the title of this submission, can you add `Show HN: ` prefix?

See https://news.ycombinator.com/showhn.html for details.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @12:03PM (#28672422)
Blast, I am sorry. It looks like I can't edit the title anymore. Otherwise I would make the change.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by IgorPartola on Monday September 27, 2021 @10:16AM (#28670906)
This looks great! I wonder how long it’ll be until someone posts a long ask snippet that will do something similar and claim this isn’t progress, but rest assured that they are wrong. I’m adding tv to my toolbox.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @10:27AM (#28671034)
Thanks! I appreciate the compliment!
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by berlinquin on Monday September 27, 2021 @11:19AM (#28671738)
Cool project! I'm familiar with column, and this looks like a good replacement.

Curious, how do you handle formatting on cells with long strings that need to overflow to multiple lines? As soon as you try to optimize the column widths for table length, you start hitting an NP-hard problem.

https://quintenkent.com/content/column-problem.html

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by flusteredBias on Monday September 27, 2021 @11:42AM (#28672070)
I actually read that article when I started making the package. You can see some of the input data here https://github.com/alexhallam/tv/blob/main/data/a.csv. I let the user chose how long the max column width should me then append "...". The default value is 20 characters.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by mileza on Monday September 27, 2021 @10:27AM (#28671031)
I think it's a great first effort, but there are a number of possible improvements to do. The most obvious one would be to support passing the file as an argument instead of using cat or the redirection operator every time. It's great that it works with stdin to allow piping into it, but it's cumbersome if you just want to take a file and print it, which will no doubt be a common use case.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by MobiusHorizons on Monday September 27, 2021 @11:00AM (#28671451)
Do you think ‘tv <file.csv’ does what you want well enough? What is the behavior when you run ‘tv file.csv’ does it just block waiting for input?

I think it’s great for a visualizer like this to encourage people to get used to the power of shell pipelines if possible.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by GuB-42 on Monday September 27, 2021 @01:22PM (#28673490)
It works, but almost all UNIX commands that work on pipelines can take a list of files as arguments. Out of the commands I use regularly, "patch" is the only one that works exclusively from stdin, probably because file arguments have a different, somewhat obscure, and probably historical meaning.

If appropriate, using files as arguments instead of using shell pipelines is a best practice. Commands can optimize for that use case, print better error messages, etc...

And it is not a good thing to encourage useless use of cat. If you goal is to show how your tool is to be used with pipelines, show an actually useful pipeline for example "sed '1b;/abc/!d' file.csv | tv". The "sed" command prints the first line (header), and all lines containing "abc".

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by MobiusHorizons on Tuesday September 28, 2021 @11:26AM (#28683931)
Fair enough.
Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by Someone on Monday September 27, 2021 @12:13PM (#28672552)
I think it’s a bad idea to go against half a century of conventions without good reason.

It’s very surprising to see a tool that only works as a filter, and doesn’t take file paths as arguments.

Re:Show HN: Tidy Viewer – a cross-platform CSV pretty printe... by sneak on Monday September 27, 2021 @01:13PM (#28673391)
Your asciinema playback made me twitch. Is the lack of a trailing space in your PS1 intentional?