comparison 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
comparison
equal deleted inserted replaced
17805:21c93988ca70 17806:dc7010ed0101
2992 if opts.get('all'): 2992 if opts.get('all'):
2993 iter = difflinestates(pstates, states) 2993 iter = difflinestates(pstates, states)
2994 else: 2994 else:
2995 iter = [('', l) for l in states] 2995 iter = [('', l) for l in states]
2996 for change, l in iter: 2996 for change, l in iter:
2997 cols = [fn, str(rev)] 2997 cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')]
2998 before, match, after = None, None, None 2998 before, match, after = None, None, None
2999
2999 if opts.get('line_number'): 3000 if opts.get('line_number'):
3000 cols.append(str(l.linenum)) 3001 cols.append((str(l.linenum), 'grep.linenumber'))
3001 if opts.get('all'): 3002 if opts.get('all'):
3002 cols.append(change) 3003 cols.append((change, 'grep.change'))
3003 if opts.get('user'): 3004 if opts.get('user'):
3004 cols.append(ui.shortuser(ctx.user())) 3005 cols.append((ui.shortuser(ctx.user()), 'grep.user'))
3005 if opts.get('date'): 3006 if opts.get('date'):
3006 cols.append(datefunc(ctx.date())) 3007 cols.append((datefunc(ctx.date()), 'grep.date'))
3007 if opts.get('files_with_matches'): 3008 if opts.get('files_with_matches'):
3008 c = (fn, rev) 3009 c = (fn, rev)
3009 if c in filerevmatches: 3010 if c in filerevmatches:
3010 continue 3011 continue
3011 filerevmatches[c] = 1 3012 filerevmatches[c] = 1
3012 else: 3013 else:
3013 before = l.line[:l.colstart] 3014 before = l.line[:l.colstart]
3014 match = l.line[l.colstart:l.colend] 3015 match = l.line[l.colstart:l.colend]
3015 after = l.line[l.colend:] 3016 after = l.line[l.colend:]
3016 ui.write(sep.join(cols)) 3017 for col, label in cols[:-1]:
3018 ui.write(col, label=label)
3019 ui.write(sep, label='grep.sep')
3020 ui.write(cols[-1][0], label=cols[-1][1])
3017 if before is not None: 3021 if before is not None:
3022 ui.write(sep, label='grep.sep')
3018 if not opts.get('text') and binary(): 3023 if not opts.get('text') and binary():
3019 ui.write(sep + " Binary file matches") 3024 ui.write(" Binary file matches")
3020 else: 3025 else:
3021 ui.write(sep + before) 3026 ui.write(before)
3022 ui.write(match, label='grep.match') 3027 ui.write(match, label='grep.match')
3023 ui.write(after) 3028 ui.write(after)
3024 ui.write(eol) 3029 ui.write(eol)
3025 found = True 3030 found = True
3026 return found 3031 return found