1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-14 20:23:54 +03:00

samba-tool: --color=auto looks at stderr and stdout

More often than not we are using colour in stderr, but are deciding
based on stdout's tty-ness. This patch changes to use both, and will
affect the following situation:

 samba-tool  2>/tmp/errors   # used to be colour, now not.

of course, if you want colour, you can always

 samba-tool --color=yes 2>/tmp/errors

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall
2022-09-09 15:24:29 +12:00
committed by Andrew Bartlett
parent 7d4387d15d
commit c0d0c13670
2 changed files with 10 additions and 7 deletions

View File

@@ -90,7 +90,7 @@ def xterm_256_colour(n, bg=False, bold=False):
return "\033[%s%s;5;%dm" % (weight, target, int(n))
def is_colour_wanted(stream, hint='auto'):
def is_colour_wanted(*streams, hint='auto'):
"""The hint is presumably a --color argument.
We follow the behaviour of GNU `ls` in what we accept.
@@ -116,13 +116,14 @@ def is_colour_wanted(stream, hint='auto'):
# Note: per spec, we treat the empty string as if unset.
return False
if (hasattr(stream, 'isatty') and stream.isatty()):
return True
return False
for stream in streams:
if not stream.isatty():
return False
return True
def colour_if_wanted(stream, hint='auto'):
wanted = is_colour_wanted(stream, hint)
def colour_if_wanted(*streams, hint='auto'):
wanted = is_colour_wanted(*streams, hint=hint)
if wanted:
switch_colour_on()
else: