mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-14 10:24:47 +00:00
checkkconfigsymbols.py: add --no-color option, don't print color to non-TTY
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> Acked-by: Valentin Rothberg <valentinrothberg@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
694d0d0bb2
commit
4c73c0882b
1 changed files with 10 additions and 2 deletions
|
@ -82,6 +82,11 @@ def parse_options():
|
||||||
default=False,
|
default=False,
|
||||||
help="Reset current Git tree even when it's dirty.")
|
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()
|
(opts, _) = parser.parse_args()
|
||||||
|
|
||||||
if opts.commit and opts.diff:
|
if opts.commit and opts.diff:
|
||||||
|
@ -116,6 +121,9 @@ def main():
|
||||||
"""Main function of this module."""
|
"""Main function of this module."""
|
||||||
opts = parse_options()
|
opts = parse_options()
|
||||||
|
|
||||||
|
global color
|
||||||
|
color = opts.color and sys.stdout.isatty()
|
||||||
|
|
||||||
if opts.sim and not opts.commit and not opts.diff:
|
if opts.sim and not opts.commit and not opts.diff:
|
||||||
sims = find_sims(opts.sim, opts.ignore)
|
sims = find_sims(opts.sim, opts.ignore)
|
||||||
if sims:
|
if sims:
|
||||||
|
@ -202,14 +210,14 @@ def yel(string):
|
||||||
"""
|
"""
|
||||||
Color %string yellow.
|
Color %string yellow.
|
||||||
"""
|
"""
|
||||||
return "\033[33m%s\033[0m" % string
|
return "\033[33m%s\033[0m" % string if color else string
|
||||||
|
|
||||||
|
|
||||||
def red(string):
|
def red(string):
|
||||||
"""
|
"""
|
||||||
Color %string red.
|
Color %string red.
|
||||||
"""
|
"""
|
||||||
return "\033[31m%s\033[0m" % string
|
return "\033[31m%s\033[0m" % string if color else string
|
||||||
|
|
||||||
|
|
||||||
def execute(cmd):
|
def execute(cmd):
|
||||||
|
|
Loading…
Add table
Reference in a new issue