tty-table icon indicating copy to clipboard operation
tty-table copied to clipboard

Allow table rotation and resizing to be disabled

Open WilliamMcCumstie opened this issue 5 years ago • 5 comments
trafficstars

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:

  1. When resize: false the table is rotated, or
  2. When resize: true the 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.

WilliamMcCumstie avatar Nov 13 '20 14:11 WilliamMcCumstie

Coverage Status

Coverage increased (+0.007%) to 98.364% when pulling 9b326fcbe04968463da58c000fbb1dd5ce178243 on openflighthpc:master into 052d2725d730abe12a6f00373df56d1a997f7aa6 on piotrmurach:master.

coveralls avatar Nov 13 '20 14:11 coveralls

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?

piotrmurach avatar Nov 13 '20 19:11 piotrmurach

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.

WilliamMcCumstie avatar Nov 16 '20 09:11 WilliamMcCumstie

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.

piotrmurach avatar Nov 16 '20 19:11 piotrmurach

Okay I've added the rotate flag as requested

WilliamMcCumstie avatar Nov 17 '20 10:11 WilliamMcCumstie