Add support for wrapping with newlines#88
Conversation
It can be useful to more accurately control formatting in table cells by means of inserting newlines. For example, we can now put bulleted lists or pretty-printed JSON objects in table cells. This change makes it so that any '\n' characters encountered in the cell's values will be translated into line breaks. Implementation note: the cell wrapping logic that used to be duplicated between `mapDataUsingRowHeightIndex` and `calculateCellHeight` has been moved to `wrapCell` to be shared between them.
Pull Request Test Coverage Report for Build 141
💛 - Coveralls |
| } | ||
|
|
||
| return Math.ceil(stringWidth(value) / columnWidth); | ||
| return wrapCell(value, columnWidth, useWrapWord).length; |
There was a problem hiding this comment.
Is length safe to use here?
Does it handle ansi?
I think not.
I think you need to use string-width.
Please add a test case with ansi characters.
There was a problem hiding this comment.
This is an array, so I would imagine .length is safe to use.
I will add the test case. What are you looking for, ANSI-wise?
There was a problem hiding this comment.
All good – misunderstood the change.
Thank you for adding the test case.
|
🎉 This PR is included in version 5.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Ha, oops. Turns out it works at the internal level of the table, but the |
|
🎉 This issue has been resolved in version 5.2.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
cli-tableis causing more issues after all, and this package seems overall more solid except for the absence of line wrapping. After the discussion in #9, here's a PR that adds support.It can be useful to more accurately control formatting in table cells by
means of inserting newlines. For example, we can now put bulleted lists
or pretty-printed JSON objects in table cells.
This change makes it so that any '\n' characters encountered in the
cell's values will be translated into line breaks.
Implementation note: the cell wrapping logic that used to be duplicated
between
mapDataUsingRowHeightIndexandcalculateCellHeighthas beenmoved to
wrapCellto be shared between them.