tty-table
tty-table copied to clipboard
Allow table rotation and resizing to be disabled
I've been having a couple of issues with the resize feature and external pagers. When rendering an extra large table with less, one of the two happens:
- When
resize: falsethe table is rotated, or - When
resize: truethe table is shrunk.
This occurs because the terminal width is not "technically increased" by the pager. However in practice the width is infinitely large. Instead it would be useful if the resizing and rotation feature can be disabled entirely.
I have updated ColumnConstraint to support a resize: nil option which disables the terminal width check. This causes the table to be rendered according to its nature_width. Then a pager can handle the extra wide tables.
Both the resize: true and resize: false options are unaffected by this change add the default is still false.
Coverage increased (+0.007%) to 98.364% when pulling 9b326fcbe04968463da58c000fbb1dd5ce178243 on openflighthpc:master into 052d2725d730abe12a6f00373df56d1a997f7aa6 on piotrmurach:master.
Hi William,
Thanks for using tty-table and contributing.
Agreed, there should be a way to disable automatic rotation. I'm not sure though this is the approach I'd take to tackle this. The resize is a flag so I'm reluctant to allow for nil to be a valid value, plus nil carries no information as a value. How about adding a new rotate flag that by default would be set to true for backwards compatibility?
Okay I will look into making the change from resize: nil to some form of rotation flag.
Just one reservation about the naming of the new rotate flag. A rotate: true option sounds like it should explicitly trigger table rotation regardless of size. I am not in need of this feature however I can see scope for it in the future. Very least I don't wish to imply that is what it does.
How about a auto_rotate: true flag instead? That way the name more closely matches its purpose.
I share your naming concern. Having said that, I usually stay away from naming options auto_ even if the behaviour is indeed automatic. If rotate was a method then I would completely agree that the intention is to rotate the table right then. However, with configuration options similar to resize option, the flag name indicates a general behaviour with intention explained in the docs. In the future, the behaviour may well change without the need for changing the flag name.
Okay I've added the rotate flag as requested