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

slither: utils: respect colorization state when printing tables #2310

Merged
merged 1 commit into from
Feb 16, 2024
Merged
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
11 changes: 9 additions & 2 deletions slither/utils/myprettytable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from typing import List, Dict, Union

from prettytable import PrettyTable
from prettytable.colortable import ColorTable, Themes

from slither.utils.colors import Colors


class MyPrettyTable:
def __init__(self, field_names: List[str], pretty_align: bool = True): # TODO: True by default?
Expand All @@ -19,8 +22,12 @@ def __init__(self, field_names: List[str], pretty_align: bool = True): # TODO:
def add_row(self, row: List[Union[str, List[str]]]) -> None:
self._rows.append(row)

def to_pretty_table(self) -> ColorTable:
table = ColorTable(self._field_names, theme=Themes.OCEAN)
def to_pretty_table(self) -> PrettyTable:
if Colors.COLORIZATION_ENABLED:
table = ColorTable(self._field_names, theme=Themes.OCEAN)
else:
table = PrettyTable(self._field_names)

for row in self._rows:
table.add_row(row)
if len(self._options["set_alignment"]):
Expand Down
Loading