ajalt/mordant

Mordant 2.0 max table width

fabriziofortino opened this issue · 4 comments

I have a table with 10 columns. The text gets always truncated even if I set OverflowWrap.NORMAL. It seems there is a table max-width that I am not able to override. Is there any way to have tables with a width that depends exclusively on the content?

ajalt commented

Tables don't have a max width, but they are limited to the terminal.info.width. If you don't set this manually in the Terminal constructor, it is detected based on the environment. For JS and native, it should detect your terminal size automatically. On JVM, it will default to 72 columns for terminals that don't set the COLS environment variable (which most don't).

Before you print the table, you can call terminal.info.updateTerminalSize() to detect the width accurately. On JVM this requires calling out to a subprocess which can take anywhere from 10ms to 100ms, which is why it isn't done automatically.

I use iTerm2 and I think this happens: the width is limited to the terminal initial width. The width does not get updated if the terminal gets resized. I confirm that using updateTerminalSize fixes the issue.

On a separate note, I have cells with \n but they get removed when the table is rendered. Is this intended?

ajalt commented

It should be possible to add a function like terminal.info.listenForResize() that would listen for terminal size changes and automatically detect the new size.

For cell whitespace, the default is Whitespace.NORMAL, which collapses newlines. It would probably be less surprising to use if I changed the default to Whitespace.PRE, which would match the default for terminal.print. Either way, you can set the whitespace behavior manually with cell(Text("...", whitespace=Whitespace.PRE))

Whitespace.PRE does the trick. It would be nice if the default could be overridden because I need to change most of the cells.