Skip to content
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

Merged
merged 3 commits into from
Jan 11, 2019
Merged

Add support for wrapping with newlines #88

merged 3 commits into from
Jan 11, 2019

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jan 11, 2019

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 and calculateCellHeight has been
moved to wrapCell to be shared between them.

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.
@coveralls
Copy link

coveralls commented Jan 11, 2019

Pull Request Test Coverage Report for Build 141

  • 11 of 12 (91.67%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.8%) to 73.567%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/wrapCell.js 7 8 87.5%
Totals Coverage Status
Change from base Build 137: 0.8%
Covered Lines: 166
Relevant Lines: 227

💛 - Coveralls

}

return Math.ceil(stringWidth(value) / columnWidth);
return wrapCell(value, columnWidth, useWrapWord).length;
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

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.

@gajus gajus merged commit 3d1d8b9 into gajus:master Jan 11, 2019
@gajus
Copy link
Owner

gajus commented Jan 11, 2019

🎉 This PR is included in version 5.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jan 11, 2019
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Jan 14, 2019

Ha, oops.

Turns out it works at the internal level of the table, but the \n characters are still rejected by validateTableData() :(

@gajus
Copy link
Owner

gajus commented Feb 10, 2019

🎉 This issue has been resolved in version 5.2.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants