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

Multi line strings are not pretty-printed properly #285

Closed
2 tasks done
MarcCoquand opened this issue Aug 10, 2024 · 2 comments
Closed
2 tasks done

Multi line strings are not pretty-printed properly #285

MarcCoquand opened this issue Aug 10, 2024 · 2 comments

Comments

@MarcCoquand
Copy link

MarcCoquand commented Aug 10, 2024

Prerequisites

  • make sure you're are using the latest version by csvtk version
  • read the usage

Version is 0.30

Describe your issue

If you have a csv with multi-line strings and want to pretty print it, the rendering
is not what is expected.

For example

some,example,here
string1,"multiline
string",string2
more, text,"here
it overflows"
more,data,here

gets shown as

$ cat test2.csv | csvtk pretty -S grid
+---------+------------------+-------------+
| some    | example          | here        |
+=========+==================+=============+
| string1 | multiline
string  | string2     |
+---------+------------------+-------------+
| more    |  text            | here
it overflows  |
+---------+------------------+-------------+
| more    | data             | here        |
+---------+------------------+-------------+

whereas I think the multi-line text should be rendered within their respective column (like in excel and csvlens).

Here is kinda what I would expect it to look like (except the padding is a bit off):

+---------+------------------+-------------+
| some    | example          | here        |
+=========+==================+=============+
| string1 | multiline        | string2     |
|         | string           |             |
+---------+------------------+-------------+
| more    |  text            | here        |
|         |                  | it overflows|
+---------+------------------+-------------+
| more    | data             | here        |
+---------+------------------+-------------+

This is tested with the default, plain and grid format, but I suspect it applies to all formats.

@MarcCoquand MarcCoquand changed the title Multi line strings are not rendered properly Multi line strings are not pretty-printed properly Aug 10, 2024
@shenwei356
Copy link
Owner

Yes, it's not supported.

@shenwei356
Copy link
Owner

I convert "\n" and other symbols to " ". Available at https://github.com/shenwei356/csvtk/releases/tag/v0.32.0 .

See the convert table here: https://github.com/shenwei356/stable/blob/v0.2.0/table.go#L57-L65

$ cat test2.csv | csvtk pretty -S grid
+---------+------------------+-------------------+
| some    | example          | here              |
+=========+==================+===================+
| string1 | multiline string | string2           |
+---------+------------------+-------------------+
| more    |  text            | here it overflows |
+---------+------------------+-------------------+
| more    | data             | here              |
+---------+------------------+-------------------+

And you can set the max and min width for each column.

$  cat test2.csv | csvtk pretty -S grid -w 10 -W 0,15,15
+------------+-----------------+-----------------+
| some       | example         | here            |
+============+=================+=================+
| string1    | multiline       | string2         |
|            | string          |                 |
+------------+-----------------+-----------------+
| more       |  text           | here it         |
|            |                 | overflows       |
+------------+-----------------+-----------------+
| more       | data            | here            |
+------------+-----------------+-----------------+

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

No branches or pull requests

2 participants