diff --git a/bandit/cli/main.py b/bandit/cli/main.py index fd436d1f5..c78d5ef7b 100644 --- a/bandit/cli/main.py +++ b/bandit/cli/main.py @@ -265,7 +265,15 @@ def main(): ' not be listed in "low".', choices=["all", "low", "medium", "high"], ) - output_format = "screen" if sys.stdout.isatty() else "txt" + output_format = ( + "screen" + if ( + sys.stdout.isatty() + and os.getenv("NO_COLOR") is None + and os.getenv("TERM") != "dumb" + ) + else "txt" + ) parser.add_argument( "-f", "--format", diff --git a/bandit/core/manager.py b/bandit/core/manager.py index ddfa04573..1f9b39e41 100644 --- a/bandit/core/manager.py +++ b/bandit/core/manager.py @@ -163,7 +163,15 @@ def output_results( try: formatters_mgr = extension_loader.MANAGER.formatters_mgr if output_format not in formatters_mgr: - output_format = "screen" if sys.stdout.isatty() else "txt" + output_format = ( + "screen" + if ( + sys.stdout.isatty() + and os.getenv("NO_COLOR") is None + and os.getenv("TERM") != "dumb" + ) + else "txt" + ) formatter = formatters_mgr[output_format] report_func = formatter.plugin