Settings

Theme

Show HN: TableTennis, a new rubygem for printing stylish tables in your terminal

github.com

5 points by gurgeous 8 months ago · 1 comment

Reader

gurgeousOP 8 months ago

This got some attention in r/ruby so I figured I'd post it here too..

TableTennis is a new gem for printing stylish tables in your terminal. We've used ad-hoc versions of this in our data projects for years, and I decided to bite the bullet and release it as a proper gem.

- auto-theme to pick light or dark based on your terminal background - auto-layout to fit your terminal window - auto-format floats and dates - auto-color numeric columns - titles, row numbers, zebra stripes...

By far the hardest part is detecting the terminal background color so we can pick light vs dark theme for the table. This requires putting the console into raw mode and sending some magic queries. These queries are widely supported but not universal. There are some great libraries for doing this in Go & Rust, but as far as I know nothing like it exists for Ruby. Check out the long comment at the bottom of this helper if you are curious:

https://github.com/gurgeous/table_tennis/blob/main/lib/table...

As always, feedback, feature requests and contributions are welcome.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection