From b66b3e091f3352c975937972f767ff5ee86f3fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Fri, 16 Feb 2024 16:26:28 -0300 Subject: [PATCH] slither: utils: respect colorization state when printing tables Closes #2229 --- slither/utils/myprettytable.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/slither/utils/myprettytable.py b/slither/utils/myprettytable.py index d67f570c0..b33fb9c5f 100644 --- a/slither/utils/myprettytable.py +++ b/slither/utils/myprettytable.py @@ -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? @@ -19,8 +22,12 @@ class MyPrettyTable: 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"]):