Mercurial > public > mercurial-scm > hg
diff mercurial/commands.py @ 17806:dc7010ed0101
grep: colorize all fields
Colors were picked in accordance to GNU grep.
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sun, 14 Oct 2012 20:27:55 +0200 |
parents | 1e30c1bbd8c0 |
children | b11d181b87ba |
line wrap: on
line diff
--- a/mercurial/commands.py Sun Oct 14 20:40:23 2012 +0200 +++ b/mercurial/commands.py Sun Oct 14 20:27:55 2012 +0200 @@ -2994,16 +2994,17 @@ else: iter = [('', l) for l in states] for change, l in iter: - cols = [fn, str(rev)] + cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')] before, match, after = None, None, None + if opts.get('line_number'): - cols.append(str(l.linenum)) + cols.append((str(l.linenum), 'grep.linenumber')) if opts.get('all'): - cols.append(change) + cols.append((change, 'grep.change')) if opts.get('user'): - cols.append(ui.shortuser(ctx.user())) + cols.append((ui.shortuser(ctx.user()), 'grep.user')) if opts.get('date'): - cols.append(datefunc(ctx.date())) + cols.append((datefunc(ctx.date()), 'grep.date')) if opts.get('files_with_matches'): c = (fn, rev) if c in filerevmatches: @@ -3013,12 +3014,16 @@ before = l.line[:l.colstart] match = l.line[l.colstart:l.colend] after = l.line[l.colend:] - ui.write(sep.join(cols)) + for col, label in cols[:-1]: + ui.write(col, label=label) + ui.write(sep, label='grep.sep') + ui.write(cols[-1][0], label=cols[-1][1]) if before is not None: + ui.write(sep, label='grep.sep') if not opts.get('text') and binary(): - ui.write(sep + " Binary file matches") + ui.write(" Binary file matches") else: - ui.write(sep + before) + ui.write(before) ui.write(match, label='grep.match') ui.write(after) ui.write(eol)