jsvn: only output ANSI color codes if output is a terminal
This commit is contained in:
parent
4d96b6eed8
commit
820b6d0bf2
5
jsvn
5
jsvn
@ -71,11 +71,13 @@ COLORS = {
|
||||
'cyan': 6,
|
||||
'white': 7,
|
||||
}
|
||||
using_color = False
|
||||
|
||||
###########################################################################
|
||||
# Utility Functions #
|
||||
###########################################################################
|
||||
def ansi_color(out, fg=None, bg=None, bold=False):
|
||||
if using_color:
|
||||
bc = 1 if bold else 0
|
||||
if fg is not None:
|
||||
out.write('\033[%d;%dm' % (bc, 30 + COLORS[fg]))
|
||||
@ -83,6 +85,7 @@ def ansi_color(out, fg=None, bg=None, bold=False):
|
||||
out.write('\033[%d;%dm' % (bc, 40 + COLORS[bg]))
|
||||
|
||||
def ansi_reset(out):
|
||||
if using_color:
|
||||
out.write('\033[0m')
|
||||
|
||||
def colordiff(out, line):
|
||||
@ -462,10 +465,12 @@ def root(argv, svn, out):
|
||||
# Main #
|
||||
###########################################################################
|
||||
def main(argv):
|
||||
global using_color
|
||||
realsvn = findInPath('svn')
|
||||
colorsvn = findInPath('colorsvn')
|
||||
out = sys.stdout
|
||||
using_pager = False
|
||||
using_color = sys.stdout.isatty()
|
||||
if sys.stdout.isatty():
|
||||
if not (len(argv) >= 1 and argv[0] in ('commit', 'propedit')):
|
||||
pager = 'less -FRX'
|
||||
|
Loading…
x
Reference in New Issue
Block a user