Skip to content

Implement NO_COLOR for terminal output #412

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions core/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
colors = True # Output should be colored
machine = sys.platform # Detecting the os of current system
checkplatform = platform.platform() # Get current version of OS
if machine.lower().startswith(('os', 'win', 'darwin', 'ios')):
colors = False # Colors shouldn't be displayed on mac & windows
if checkplatform.startswith("Windows-10") and int(platform.version().split(".")[2]) >= 10586:
colors = True
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):
colors = False

else :
if machine.lower().startswith(('os', 'win', 'darwin', 'ios')):
colors = False # Colors shouldn't be displayed on mac & windows
if checkplatform.startswith("Windows-10") and int(platform.version().split(".")[2]) >= 10586:
colors = True
os.system('') # Enables the ANSI

if not colors:
end = red = white = green = yellow = run = bad = good = info = que = ''
else:
Expand Down
2 changes: 2 additions & 0 deletions xsstrike.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
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',
action='store_true')
args = parser.parse_args()

# Pull all parameter values of dict from argparse namespace into local variables of name == key
Expand Down