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

Print strings with newlines and indentation #117

Closed
ljcui opened this issue May 11, 2024 · 3 comments
Closed

Print strings with newlines and indentation #117

ljcui opened this issue May 11, 2024 · 3 comments

Comments

@ljcui
Copy link

ljcui commented May 11, 2024

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
Copy link
Owner

p-ranav commented May 11, 2024

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
Copy link
Author

ljcui commented May 11, 2024

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:#109, this is I need. Expect a new release that includes this pr.

@p-ranav
Copy link
Owner

p-ranav commented May 11, 2024

Yes, I will create a new release soon.

@p-ranav p-ranav closed this as completed May 11, 2024
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