p-ranav / tabulate

Table Maker for Modern C++
MIT License
1.91k stars 134 forks source link

Print strings with newlines and indentation #117

Closed ljcui closed 4 months ago

ljcui commented 4 months ago

The code is

std::string str = R"(first line
    second line
        third line)";
std::cout << str << std::endl;

tabulate::Table table;
table.add_row({str});
std::cout << table << std::endl;

The output is

first line
    second line
        third line
+--------------------+
| first line         |
| second line        |
| third line         |
+--------------------+

Why indented strings disappear ?

p-ranav commented 4 months ago

Per the note in this section of the README:

NOTE: Whether word-wrapping is automatic or not, tabulate performs a trim operation on each line of each cell to remove whitespace characters from either side of line.

tabulate performs a trim operation. This is why the indentation disappears. This is by design.

ljcui commented 4 months ago

Per the note in this section of the README:

NOTE: Whether word-wrapping is automatic or not, tabulate performs a trim operation on each line of each cell to remove whitespace characters from either side of line.

tabulate performs a trim operation. This is why the indentation disappears. This is by design.

I don't think this is a correct design because it modifies the original string content. I found this PR:https://github.com/p-ranav/tabulate/pull/109, this is I need. Expect a new release that includes this pr.

p-ranav commented 4 months ago

Yes, I will create a new release soon.