dtolnay / request-for-implementation

Crates that don't exist, but should
610 stars 6 forks source link

Library to format and paginate tabular CLI output #15

Closed dtolnay closed 5 years ago

dtolnay commented 5 years ago

In cargo llvm-lines the program output is a table with two columns of numbers and one column of strings. I would like a super easy way to make such output look good with the minimal amount of work in my crate. Something like:

pub fn cli_table(data: Vec<Vec<String>>) -> !;

which takes care of aligning the data (right aligned for columns of numbers, left aligned for text), drawing ASCII art to make it pretty (like what bat does), and invoking the default system pager to support paging the output up and down (again similar to bat).

If the output is not a tty, the paging and ASCII art should be disabled automatically.

BurntSushi commented 5 years ago

tabwriter is a minimal thing you can use to get alignment with tab separated fields. It does not do ASCII art or pagination though.

RazrFalcon commented 5 years ago

There is prettytable-rs. But it's pretty simple.

dtolnay commented 5 years ago

Thanks, prettytable-rs looks pretty close to what I want. I like the subtle unicode line art that bat uses. Is that doable as a prettytable format?


bat screenshot

RazrFalcon commented 5 years ago

I newer used it. I wanted to use it in cargo-bloat, but it doesn't support column width, which I need.

matthias-t commented 5 years ago

Does it makes sense to use another 2-dimensional data structure instead of Vec<Vec<String>>? I'm experimenting with a Grid<T> type backed by a single Vec<T>.

Also, tabular-rs supports right- and left-aligning.

gfreezy commented 5 years ago

https://github.com/phsym/prettytable-rs/blob/fa70ca6fdb7d0d98a04961c1a74105e4f797661d/examples/formatting.rs#L64

prettytable-rs can print bat like lines.

dtolnay commented 5 years ago

Thanks all! I have removed this idea from my list since it is easily solved by using the prettytable-rs crate + pager crate which already existed when I opened this issue.