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

Respect color environment variables if set #813

Merged
merged 1 commit into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion bandit/cli/main.py
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion bandit/core/manager.py
Expand Up @@ -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
Expand Down