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:
gurgeous•3h ago
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.