Skip to content

Commit 1c3a119

Browse files
committed
implement NO_COLOR standard
https://no-color.org/
1 parent 959ba63 commit 1c3a119

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ def banner():
14001400
if not any(_ in sys.argv for _ in ("--version", "--api")) and not conf.get("disableBanner"):
14011401
result = BANNER
14021402

1403-
if not IS_TTY or any(_ in sys.argv for _ in ("--disable-coloring", "--disable-colouring")):
1403+
if not IS_TTY or conf.get("disableColoring") or any(_ in sys.argv for _ in ("--disable-coloring", "--disable-colouring")):
14041404
result = clearColors(result)
14051405
elif IS_WIN:
14061406
coloramainit()

lib/core/log.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
class _ColorizingStreamHandler(ColorizingStreamHandler):
2525
def colorize(self, message, levelno, force=False):
26+
from lib.core.data import conf # import inside function to avoid ImportError
27+
if conf.get("disableColoring"):
28+
return message
2629
if levelno in self.level_map and (self.is_tty or force):
2730
bg, fg, bold = self.level_map[levelno]
2831
params = []

sqlmap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def main():
148148
resolveCrossReferences()
149149
checkEnvironment()
150150
setPaths(modulePath())
151+
152+
# Check for NO_COLOR environment variable
153+
if os.environ.get("NO_COLOR") not in (None, ""):
154+
conf.disableColoring = True
155+
151156
banner()
152157

153158
# Store original command line options for possible later restoration

0 commit comments

Comments
 (0)