Skip to content

Commit

Permalink
Fixing color tables ignoring the --disable-color command line argumen…
Browse files Browse the repository at this point in the history
…t. Proposing a fix for #2229
  • Loading branch information
theexoticman committed Nov 11, 2023
1 parent fbd578a commit ba3d20f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion slither/utils/colors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import partial
import platform
import sys

import os

class Colors: # pylint: disable=too-few-public-methods
COLORIZATION_ENABLED = True
Expand Down Expand Up @@ -77,6 +77,8 @@ def set_colorization_enabled(enabled: bool) -> None:
else:
# This is not windows, or colorization is being disabled, so we can adjust the state immediately.
Colors.COLORIZATION_ENABLED = enabled
os.environ['DISABLE_MY_PRETTY_TABLE_COLOR'] = "false" if enabled else "true"



green = partial(colorize, Colors.GREEN)
Expand Down
9 changes: 7 additions & 2 deletions slither/utils/myprettytable.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import List, Dict, Union

from prettytable.colortable import ColorTable, Themes

import os

Check warning on line 4 in slither/utils/myprettytable.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

C0411: standard import "import os" should be placed before "from prettytable.colortable import ColorTable, Themes" (wrong-import-order)

class MyPrettyTable:

Check warning on line 7 in slither/utils/myprettytable.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

C0303: Trailing whitespace (trailing-whitespace)
def __init__(self, field_names: List[str], pretty_align: bool = True): # TODO: True by default?
self._field_names = field_names
self._rows: List = []
Expand All @@ -15,12 +16,16 @@ def __init__(self, field_names: List[str], pretty_align: bool = True): # TODO:
self._options["set_alignment"] += [(field_name, "r")]
else:
self._options["set_alignment"] = []
if os.getenv("DISABLE_MY_PRETTY_TABLE_COLOR")=="true":

Check warning on line 19 in slither/utils/myprettytable.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

C0303: Trailing whitespace (trailing-whitespace)
self.theme = Themes.DEFAULT

Check warning on line 20 in slither/utils/myprettytable.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

C0303: Trailing whitespace (trailing-whitespace)
else:
self.theme = Themes.OCEAN # keep ocean theme by default.

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)
table = ColorTable(self._field_names, theme=self.theme)
for row in self._rows:
table.add_row(row)
if len(self._options["set_alignment"]):
Expand Down

0 comments on commit ba3d20f

Please sign in to comment.