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

Fix drawing headerless colored tables with title #332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kuba2k2
Copy link

@kuba2k2 kuba2k2 commented Oct 17, 2024

The pull request #299 (issue #290) fixed drawing ColorTable with a title set. However, it didn't fix drawing such a table with header set to False.

This PR fixes that; there was some incorrect line slicing that led to ANSI codes being cut off partially.

Here's how it looks without this PR:

+-----------------------+
|        Efforts        |
+[36m+---+---+---+---+---+---+ 1 | 2 | 3 | 4 | 5 | 6 |
+---+---+---+---+---+---+

and with this PR - the correct result:

+-----------------------+
|        Efforts        |
+---+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 | 6 |
+---+---+---+---+---+---+

Produced by this code:

from prettytable import colortable

table = colortable.ColorTable(
    ("A", "B", "C", "D", "E", "f"),
    align="l",
    theme=colortable.Themes.OCEAN,
)
table.title = "Efforts"
table.header = False
table.add_row([1, 2, 3, 4, 5, 6])
print(table)

I have also added parametrized tests to the test_colortable.py, so that it will test all possible cases of header/title combinations.

@hugovk hugovk added the changelog: Fixed For any bug fixes label Oct 17, 2024
Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.57%. Comparing base (f044b0e) to head (fa57608).
Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #332      +/-   ##
==========================================
+ Coverage   94.51%   94.57%   +0.06%     
==========================================
  Files           5        5              
  Lines        2462     2637     +175     
==========================================
+ Hits         2327     2494     +167     
- Misses        135      143       +8     
Flag Coverage Δ
macos-latest 94.53% <100.00%> (+0.02%) ⬆️
ubuntu-latest 94.53% <100.00%> (+0.02%) ⬆️
windows-latest 94.49% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Fixed For any bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants