From: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
valentinrothberg@gmail.com, josh@joshtriplett.org
Subject: [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
Date: Tue, 5 Jul 2016 17:47:37 +1000 [thread overview]
Message-ID: <1467704857-831-1-git-send-email-andrew.donnellan@au1.ibm.com> (raw)
In-Reply-To: <1467621570-970-1-git-send-email-andrew.donnellan@au1.ibm.com>
Only print the ANSI colour escape codes if stdout is a TTY. Useful if
redirecting output to a file or piping to another script.
Also add a new option, --no-color, if the user wants to disable colour
output for whatever reason.
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
V1->V2:
- automatically detect non-TTYs and disable colour output.
Suggested by Josh Triplett
---
scripts/checkkconfigsymbols.py | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/scripts/checkkconfigsymbols.py b/scripts/checkkconfigsymbols.py
index df643f6..b140fc9 100755
--- a/scripts/checkkconfigsymbols.py
+++ b/scripts/checkkconfigsymbols.py
@@ -82,6 +82,11 @@ def parse_options():
default=False,
help="Reset current Git tree even when it's dirty.")
+ parser.add_option('', '--no-color', dest='color', action='store_false',
+ default=True,
+ help="Don't print colored output. Default when not "
+ "outputting to a terminal.")
+
(opts, _) = parser.parse_args()
if opts.commit and opts.diff:
@@ -116,6 +121,9 @@ def main():
"""Main function of this module."""
opts = parse_options()
+ global color
+ color = opts.color and sys.stdout.isatty()
+
if opts.sim and not opts.commit and not opts.diff:
sims = find_sims(opts.sim, opts.ignore)
if sims:
@@ -202,14 +210,14 @@ def yel(string):
"""
Color %string yellow.
"""
- return "\033[33m%s\033[0m" % string
+ return "\033[33m%s\033[0m" % string if color else string
def red(string):
"""
Color %string red.
"""
- return "\033[31m%s\033[0m" % string
+ return "\033[31m%s\033[0m" % string if color else string
def execute(cmd):
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com IBM Australia Limited
next prev parent reply other threads:[~2016-07-05 7:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-04 8:39 [PATCH] checkkconfigsymbols.py: add --no-color option Andrew Donnellan
2016-07-04 10:44 ` Valentin Rothberg
2016-07-04 12:24 ` Josh Triplett
2016-07-05 7:22 ` Andrew Donnellan
2016-07-05 7:47 ` Andrew Donnellan [this message]
2016-07-05 8:45 ` [PATCH v2] checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY Valentin Rothberg
2016-08-16 8:25 ` Valentin Rothberg
2016-08-16 10:49 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1467704857-831-1-git-send-email-andrew.donnellan@au1.ibm.com \
--to=andrew.donnellan@au1.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=valentinrothberg@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).