remove trailing blank line on colorized output piped to less

This commit is contained in:
Josh Holtrop 2012-04-07 18:35:01 -04:00
parent ae0b02ea02
commit 2b2589369f

24
jsvn
View File

@ -231,25 +231,30 @@ def ansi_reset(out):
out.write('\033[0m') out.write('\033[0m')
def colordiff(out, line): def colordiff(out, line):
line = line.strip()
if re.match(r'Index:\s', line): if re.match(r'Index:\s', line):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
return return
if re.match(r'={67}', line): if re.match(r'={67}', line):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
return return
if re.match(r'-', line): if re.match(r'-', line):
ansi_color(out, 'red') ansi_color(out, 'red')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
return return
elif re.match(r'\+', line): elif re.match(r'\+', line):
ansi_color(out, 'green') ansi_color(out, 'green')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
return return
m = re.match(r'(@@.*@@)(.*)', line) m = re.match(r'(@@.*@@)(.*)', line)
if m is None: if m is None:
@ -262,6 +267,7 @@ def colordiff(out, line):
out.write('\n') out.write('\n')
return return
out.write(line) out.write(line)
out.write('\n')
def findInPath(cmd): def findInPath(cmd):
path_entries = os.environ['PATH'].split(os.pathsep) path_entries = os.environ['PATH'].split(os.pathsep)
@ -377,8 +383,9 @@ def filter_update(pout, out):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
elif action == 'G': elif action == 'G':
ansi_color(out, 'magenta') ansi_color(out, 'magenta')
out.write(line) out.write(line.strip())
ansi_reset(out) ansi_reset(out)
out.write('\n')
continue continue
out.write(line) out.write(line)
@ -473,9 +480,10 @@ def branch(argv, svn, out):
ansi_color(out, 'green') ansi_color(out, 'green')
else: else:
out.write(' ') out.write(' ')
out.write(b + '\n') out.write(b)
if b == current: if b == current:
ansi_reset(out) ansi_reset(out)
out.write('\n')
return RET_OK return RET_OK
branch_name = argv[-1] branch_name = argv[-1]
if len(argv) >= 3 and argv[1] == "-d": if len(argv) >= 3 and argv[1] == "-d":
@ -702,6 +710,7 @@ def log(argv, svn, out):
mode = 'normal' mode = 'normal'
pout = Popen([svn] + argv, stdout=PIPE).stdout pout = Popen([svn] + argv, stdout=PIPE).stdout
for line in iter(pout.readline, ''): for line in iter(pout.readline, ''):
line = line.strip()
if mode == 'normal' and re.match(r'(r\d+)\s+\|', line): if mode == 'normal' and re.match(r'(r\d+)\s+\|', line):
parts = line.split('|') parts = line.split('|')
if len(parts) == 4: if len(parts) == 4:
@ -718,10 +727,13 @@ def log(argv, svn, out):
ansi_reset(out) ansi_reset(out)
out.write('|') out.write('|')
out.write(parts[3]) out.write(parts[3])
out.write('\n')
else: else:
out.write(line) out.write(line)
out.write('\n')
elif mode == 'normal' and re.match(r'Changed.paths:', line): elif mode == 'normal' and re.match(r'Changed.paths:', line):
out.write(line) out.write(line)
out.write('\n')
mode = 'cp' mode = 'cp'
elif mode == 'cp' and re.match(r' [ADM] ', line): elif mode == 'cp' and re.match(r' [ADM] ', line):
action = line[3] action = line[3]
@ -733,15 +745,18 @@ def log(argv, svn, out):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
elif re.match(r'-{72}', line): elif re.match(r'-{72}', line):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
mode = 'normal' mode = 'normal'
elif re.match(r'={67}', line): elif re.match(r'={67}', line):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
mode = 'diff' mode = 'diff'
elif mode == 'diff': elif mode == 'diff':
colordiff(out, line) colordiff(out, line)
@ -749,8 +764,10 @@ def log(argv, svn, out):
ansi_color(out, 'yellow') ansi_color(out, 'yellow')
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
else: else:
out.write(line) out.write(line)
out.write('\n')
return RET_OK return RET_OK
def update(argv, svn, out): def update(argv, svn, out):
@ -763,6 +780,7 @@ def status(argv, svn, out):
external_printed = True external_printed = True
pout = Popen([svn] + argv, stdout=PIPE).stdout pout = Popen([svn] + argv, stdout=PIPE).stdout
for line in iter(pout.readline, ''): for line in iter(pout.readline, ''):
line = line.strip()
m = re.match(r"Performing status on external item at '(.*)':", line) m = re.match(r"Performing status on external item at '(.*)':", line)
if m is not None: if m is not None:
external = m.group(1) external = m.group(1)
@ -789,8 +807,10 @@ def status(argv, svn, out):
continue # don't print externals continue # don't print externals
out.write(line) out.write(line)
ansi_reset(out) ansi_reset(out)
out.write('\n')
continue continue
out.write(line) out.write(line)
out.write('\n')
return RET_OK return RET_OK
def externals(argv, svn, out): def externals(argv, svn, out):