diff --git a/bandit/formatters/screen.py b/bandit/formatters/screen.py index 4a3073dbd..6d6c77b04 100644 --- a/bandit/formatters/screen.py +++ b/bandit/formatters/screen.py @@ -48,6 +48,17 @@ from bandit.core import docs_utils from bandit.core import test_properties +# This fixes terminal colors not displaying properly on Windows systems. +# Colorama will intercept any ANSI escape codes and convert them to the +# proper Windows console API calls to change text color. +if sys.platform.startswith('win32'): + try: + import colorama + except ImportError: + pass + else: + colorama.init() + LOG = logging.getLogger(__name__) COLOR = { diff --git a/requirements.txt b/requirements.txt index ab987fc90..e0d2a5b0b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ GitPython>=1.0.1 # BSD License (3 clause) PyYAML>=3.12 # MIT six>=1.10.0 # MIT stevedore>=1.20.0 # Apache-2.0 +colorama>=0.3.9;platform_system=="Windows" # BSD License (3 clause)