Skip to content

Commit

Permalink
Replace deprecated constants with enums (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Nov 3, 2024
2 parents 452771e + d6cc0d2 commit 7652bba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dynamic = [ "version" ]
dependencies = [
"httpx>=0.19",
"platformdirs",
"prettytable>=2.4",
"prettytable>=3.12",
"pytablewriter[html]>=0.63",
"python-dateutil",
"python-slugify",
Expand Down
16 changes: 9 additions & 7 deletions src/norwegianblue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,29 +227,31 @@ def _prettytable(
color: str = "yes",
title: str | None = None,
) -> str:
from prettytable import MARKDOWN, SINGLE_BORDER, PrettyTable
from prettytable import PrettyTable, TableStyle

x = PrettyTable()
x.set_style(MARKDOWN if format_ == "markdown" else SINGLE_BORDER)
table = PrettyTable()
table.set_style(
TableStyle.MARKDOWN if format_ == "markdown" else TableStyle.SINGLE_BORDER
)
do_color = color != "no" and format_ == "pretty"

for header in headers:
left_align = header in ("cycle", "latest", "link")
display_header = colored(header, attrs=["bold"]) if do_color else header
col_data = [row[header] if header in row else "" for row in data]
x.add_column(display_header, col_data)
table.add_column(display_header, col_data)

if left_align:
x.align[display_header] = "l"
table.align[display_header] = "l"

title_prefix = ""
if title:
if format_ == "pretty":
x.title = colored(title, attrs=["bold"]) if do_color else title
table.title = colored(title, attrs=["bold"]) if do_color else title
else:
title_prefix = f"## {title}\n\n"

return title_prefix + x.get_string()
return title_prefix + table.get_string()


def _pytablewriter(
Expand Down

0 comments on commit 7652bba

Please sign in to comment.