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

Add new themes to ColorTable #312

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/prettytable/colortable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,54 @@ def format_code(s: str) -> str:

class Themes:
DEFAULT = Theme()
DYSLEXIA_FRIENDLY = Theme(
default_color="38;5;223",
vertical_color="38;5;22",
horizontal_color="38;5;22",
junction_color="38;5;58",
)
EARTH = Theme(
default_color="33",
vertical_color="38;5;94",
horizontal_color="38;5;22",
junction_color="38;5;130",
)
GLARE_REDUCTION = Theme(
default_color="38;5;252",
vertical_color="38;5;240",
horizontal_color="38;5;240",
junction_color="38;5;246",
)
HIGH_CONTRAST = Theme(
default_color="97",
vertical_color="91",
horizontal_color="94",
junction_color="93",
)
LAVENDER = Theme(
default_color="38;5;183",
vertical_color="35",
horizontal_color="38;5;147",
junction_color="38;5;219",
)
OCEAN = Theme(
default_color="96",
vertical_color="34",
horizontal_color="34",
junction_color="36",
)
OCEAN_DEEP = Theme(
default_color="96",
vertical_color="34",
horizontal_color="36",
junction_color="94",
)
PASTEL = Theme(
default_color="38;5;223",
vertical_color="38;5;152",
horizontal_color="38;5;187",
junction_color="38;5;157",
)


class ColorTable(PrettyTable):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_colortable.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,19 @@ def test_color_table_rendering(self) -> None:
result = str(table)

assert expected == result

def test_all_themes(self) -> None:
"""Tests rendering with all available themes"""
table = ColorTable(
("A", "B", "C", "D", "E", "F"),
)
table.title = "Theme Test"
table.add_row([1, 2, 3, 4, 5, 6])

for theme_name, theme in vars(Themes).items():
if isinstance(theme, Theme):
table.theme = theme
result = str(table)
print(f"\n{theme_name} Theme:")
print(result)
Comment on lines +171 to +172
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove printing from the tests:

Suggested change
print(f"\n{theme_name} Theme:")
print(result)

assert result # Simple check to ensure rendering doesn't fail
Loading