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

How could I use newline characters? #9

Closed
destec opened this issue Sep 28, 2015 · 15 comments
Closed

How could I use newline characters? #9

destec opened this issue Sep 28, 2015 · 15 comments

Comments

@destec
Copy link

destec commented Sep 28, 2015

I want to start a new line in a single cell, so I tried to add '\r\n' or '\n' at the end of the line. But it seems like it will be forbidden because of the regex test in validateData.js line 58: /[\x01-\x1A]/.test(cell). So is there any way to have a new line?

@gajus
Copy link
Owner

gajus commented Oct 1, 2015

How is the output supposed to look?

@gajus
Copy link
Owner

gajus commented Oct 1, 2015

I am writing V3 at the moment. This sounds like a breaking change. Therefore, it would be a good time to contribute thoughts about newline character support.

@gajus
Copy link
Owner

gajus commented Oct 1, 2015

I was thinking more of this and I cannot see a valid use case for a newline character in the context of a tabular data. If you can provide an example, I will add this for future consideration.

@destec
Copy link
Author

destec commented Oct 2, 2015

Thanks for your concern @gajus . What I really need is to have multiple line in one cell for some reason. A bad code was like

var element1 = "a single line works perfect"
var element2 = "the first line \r\n  the second line \r\n  the third line"

var data = [[1, 2], [element1, element2]];

console.log(table(data));

As you can see, in the variable element2 I want to split the content into three lines and I used \r\n as the symbol but it would have an error just I wrote before. And below is what I think it would look like:

1 2
a single line works perfect the first line
the second line
the third line

@gajus
Copy link
Owner

gajus commented Oct 4, 2015

There is no way to force a new line other than restricting the column width. As a simple workaround, I suggest to simply replace all instances of newline with a custom character that would visually indicate a line break, e.g. literal \n.

@gajus
Copy link
Owner

gajus commented Dec 9, 2016

Since @shellscape has brought this up again:

I don't remember the reason for not supporting a new line character. As far as I remember, my reasoning was that this is a fairly edge case requirement and it would introduce a considerable level of code complexity to support it without running into edge cases.

@shellscape
Copy link

haha "hellscape" that sounds ominous. I don't think it's as edge-casey as it might seem. Aside from text-table, nearly every other table-printing module out there supports it. I was drawn in by the simple use and setup of table. The alternative is to add rows with empty cells to fake a line break in a particular cell, and that's mighty hacky.

@gajus
Copy link
Owner

gajus commented Dec 9, 2016

Sorry, copy-paste failure. :-)

I am certainly open to a PR.

@gajus gajus reopened this Dec 9, 2016
@fogine
Copy link

fogine commented Feb 21, 2017

Another use case would be pretty-printing json schema into one of the columns, eg:

type schema
text { prop: { \n prop2: 'value', \n prop3: 'value' \n } \n }

In my case the schema is more complex with custom syntax highlighting. It does not make sense to transform it into another table.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 23, 2018

I will second a feature request for this. Lack of this feature is a deal breaker for me.

I was thinking more of this and I cannot see a valid use case for a newline character in the context of a tabular data

Well it might turn out that your users have different use cases than you can imagine. In my case, I want to show structured complex data in each cell (lists of strings => newline separated strings, JSON => pretty-printed JSON).

You might want to put a disclaimer at the top of the description that is this library is explicitly not intended for use cases where you want to show something more than single scalar value in a cell.

@gajus
Copy link
Owner

gajus commented Nov 23, 2018

I will second a feature request for this. Lack of this feature is a deal breaker for me.

Please contribute if this feature is important for you.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 23, 2018

Fair enough request. I notice myself sounding like an entitled internet person, sorry for that.

In the mean time I've found a different library that does what I want, so I'm good :). Thanks for the response though.

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 27, 2018

Ha, turns out I settled on cli-table, the thing you originally forked!

Automattic/cli-table#79

@gajus
Copy link
Owner

gajus commented Nov 27, 2018

table is not a fork of cli-table.

Glad you found whats working for you though.

@PADMAARUN

This comment has been minimized.

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

No branches or pull requests

6 participants