Skip to content

Respect line breaks in cell content? #112

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

Closed
SanctusAnimus opened this issue Oct 19, 2023 · 3 comments · Fixed by #113
Closed

Respect line breaks in cell content? #112

SanctusAnimus opened this issue Oct 19, 2023 · 3 comments · Fixed by #113
Labels
bug Something isn't working

Comments

@SanctusAnimus
Copy link

SanctusAnimus commented Oct 19, 2023

So consider following table:

table2ascii(
        header=["Rank", "Abilities"],
        body=[
            [1, 'Fury Swipes\nWukong`s Command\nMarksmanship\nOmnislash\nSoul Assumption']
        ],
        alignments=[Alignment.CENTER, Alignment.RIGHT],
        column_widths=[6, 19]
    )

Basically what i want is that every ability name to be on a new line, inside a cell

What i get instead is this:

╔══════════════════════════╗
║ Rank           Abilities ║
╟──────────────────────────╢
║  1           Fury Swipes ║
║         Wukong`s Command ║
║             Marksmanship ║
║           Omnislash Soul ║
║               Assumption ║
╚══════════════════════════╝

Note how Omnislash is merged with Soul in this case, while Assumption is moved to a new line.

Is there a sane way to avoid this (especially without replacing spaces in names with characters or w/e), or tell library to respect line breaks?

@DenverCoder1 DenverCoder1 added the bug Something isn't working label Oct 19, 2023
@DenverCoder1
Copy link
Owner

DenverCoder1 commented Oct 20, 2023

Thanks for reporting!

It seems like this issue is caused by the use of textwrap.fill (table_to_ascii.py#L309) which internally removes whitespace before redividing the lines.

We probably could resolve this by checking if the widest line is already smaller than the cell's inner width and not use textwrap.fill when it's not needed such as in your example.

@DenverCoder1
Copy link
Owner

Feel free to let me know what you think of this solution

@SanctusAnimus
Copy link
Author

Thanks for swift response and effort!
I'll be honest, i'm not acknowledged with internals of this library, so whatever fixes the issue itself works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants