-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-table
is 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
mapDataUsingRowHeightIndex
andcalculateCellHeight
has beenmoved to
wrapCell
to be shared between them.