Skip to content

Implement NO_COLOR for terminal output #412

Open
FlorianLatapie wants to merge 3 commits intos0md3v:masterfrom
FlorianLatapie:master
Open

Implement NO_COLOR for terminal output #412
FlorianLatapie wants to merge 3 commits intos0md3v:masterfrom
FlorianLatapie:master

Conversation

@FlorianLatapie
Copy link
Copy Markdown

@FlorianLatapie FlorianLatapie commented Aug 2, 2024

See https://no-color.org

What does it implement/fix? Explain your changes.

Where has this been tested?

Python Version: python3.11
Operating System: Windows 11, Debian GNU/Linux 12 (bookworm) on Windows 10 x86_64 (WSL)

Does this close any currently open issues?

no

Does this add any new dependency?

no

Does this add any new command line switch/option?

yes : --no-color or use env variable NO_COLOR="1"

Any other comments you would like to make?

Some Questions

  • I have documented my code.
  • I have tested my build before submitting the pull request.

Copilot AI review requested due to automatic review settings March 22, 2026 17:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for disabling colored terminal output via the NO_COLOR environment variable (per no-color.org) and a new --no-color CLI flag.

Changes:

  • Introduces a --no-color argparse flag in the main entrypoint.
  • Updates color initialization logic to disable ANSI colors when NO_COLOR is present or --no-color is passed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
xsstrike.py Adds a new --no-color CLI option to control colored output.
core/colors.py Disables color output when NO_COLOR or --no-color is detected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xsstrike.py
Comment on lines +83 to 85
parser.add_argument('--no-color', help='disable colored output', dest='no_color',
action='store_true')
args = parser.parse_args()
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--no-color is added to argparse, but args.no_color is never read anywhere in this entrypoint. Right now color disabling relies on core/colors.py inspecting sys.argv at import time, which makes the CLI flag handling split across modules and easy to break during refactors. Consider either (a) handling --no-color entirely in xsstrike.py (e.g., pre-scan sys.argv and set NO_COLOR/a shared config flag before importing core.colors), or (b) parsing args before importing/using core.colors, so the flag is applied in one place.

Copilot uses AI. Check for mistakes.
Comment thread xsstrike.py
choices=core.log.log_config.keys(), default=None)
parser.add_argument('--log-file', help='Name of the file to log', dest='log_file',
default=core.log.log_file)
parser.add_argument('--no-color', help='disable colored output', dest='no_color',
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace at the end of this line (after the comma). This tends to create noisy diffs and can fail linting in some environments; please trim it.

Suggested change
parser.add_argument('--no-color', help='disable colored output', dest='no_color',
parser.add_argument('--no-color', help='disable colored output', dest='no_color',

Copilot uses AI. Check for mistakes.
Comment thread core/colors.py
if ('NO_COLOR' in os.environ) or ('--no-color' in sys.argv):
colors = False

else :
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8 formatting: else : should be else: (no space before the colon) to match standard Python style and reduce formatter/linter churn.

Suggested change
else :
else:

Copilot uses AI. Check for mistakes.
Comment thread core/colors.py
os.system('') # Enables the ANSI

# Check for NO_COLOR environment variable, see https://no-color.org
if ('NO_COLOR' in os.environ) or ('--no-color' in sys.argv):
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having core/colors.py inspect sys.argv couples this core module to a specific CLI option and makes color behavior depend on import-time process arguments (which can be surprising when the module is reused). If possible, keep core/colors.py driven by environment/config only (e.g., honor NO_COLOR here) and let the entrypoint translate --no-color into that config before importing/using core.colors.

Suggested change
if ('NO_COLOR' in os.environ) or ('--no-color' in sys.argv):
if 'NO_COLOR' in os.environ:

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants