comparison hgext/color.py @ 7419:efe31fbe6cf0

color: don't run status twice for -n Just cut off the status characters.
author Brendan Cully <brendan@kublai.com>
date Tue, 25 Nov 2008 18:32:44 -0800
parents 0e04753de3ec
children c9fd5474a707
comparison
equal deleted inserted replaced
7418:0e04753de3ec 7419:efe31fbe6cf0
92 def colorstatus(orig, ui, repo, *pats, **opts): 92 def colorstatus(orig, ui, repo, *pats, **opts):
93 '''run the status command with colored output''' 93 '''run the status command with colored output'''
94 94
95 delimiter = opts['print0'] and '\0' or '\n' 95 delimiter = opts['print0'] and '\0' or '\n'
96 96
97 # run status and capture it's output 97 nostatus = opts.get('no_status')
98 opts['no_status'] = False
99 # run status and capture its output
98 ui.pushbuffer() 100 ui.pushbuffer()
99 retval = orig(ui, repo, *pats, **opts) 101 retval = orig(ui, repo, *pats, **opts)
100 # filter out empty strings 102 # filter out empty strings
101 lines = [ line for line in ui.popbuffer().split(delimiter) if line ] 103 lines_with_status = [ line for line in ui.popbuffer().split(delimiter) if line ]
102 104
103 if opts['no_status']: 105 if nostatus:
104 # if --no-status, run the command again without that option to get 106 lines = [l[2:] for l in lines_with_status]
105 # output with status abbreviations
106 opts['no_status'] = False
107 ui.pushbuffer()
108 orig(ui, repo, *pats, **opts)
109 # filter out empty strings
110 lines_with_status = [ line for
111 line in ui.popbuffer().split(delimiter) if line ]
112 else: 107 else:
113 lines_with_status = lines 108 lines = lines_with_status
114 109
115 # apply color to output and display it 110 # apply color to output and display it
116 for i in xrange(0, len(lines)): 111 for i in xrange(0, len(lines)):
117 status = _status_abbreviations[lines_with_status[i][0]] 112 status = _status_abbreviations[lines_with_status[i][0]]
118 effects = _status_effects[status] 113 effects = _status_effects[status]