comparison hgext/color.py @ 31115:f5131d4f512a

color: move 'styles' definition on the 'ui' object Same logic as for '_terminfoparams'. The content depends on the config so it should be specific to each 'ui instance.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sun, 06 Nov 2016 20:16:01 +0100
parents 268caf97c38f
children c4e8fa2b1c40
comparison
equal deleted inserted replaced
31114:1613c55ad3d6 31115:f5131d4f512a
205 return _debugdisplaystyle(ui) 205 return _debugdisplaystyle(ui)
206 else: 206 else:
207 return _debugdisplaycolor(ui) 207 return _debugdisplaycolor(ui)
208 208
209 def _debugdisplaycolor(ui): 209 def _debugdisplaycolor(ui):
210 oldstyle = color._styles.copy() 210 oldstyle = ui._styles.copy()
211 try: 211 try:
212 color._styles.clear() 212 ui._styles.clear()
213 for effect in color._effects.keys(): 213 for effect in color._effects.keys():
214 color._styles[effect] = effect 214 ui._styles[effect] = effect
215 if ui._terminfoparams: 215 if ui._terminfoparams:
216 for k, v in ui.configitems('color'): 216 for k, v in ui.configitems('color'):
217 if k.startswith('color.'): 217 if k.startswith('color.'):
218 color._styles[k] = k[6:] 218 ui._styles[k] = k[6:]
219 elif k.startswith('terminfo.'): 219 elif k.startswith('terminfo.'):
220 color._styles[k] = k[9:] 220 ui._styles[k] = k[9:]
221 ui.write(_('available colors:\n')) 221 ui.write(_('available colors:\n'))
222 # sort label with a '_' after the other to group '_background' entry. 222 # sort label with a '_' after the other to group '_background' entry.
223 items = sorted(color._styles.items(), 223 items = sorted(ui._styles.items(),
224 key=lambda i: ('_' in i[0], i[0], i[1])) 224 key=lambda i: ('_' in i[0], i[0], i[1]))
225 for colorname, label in items: 225 for colorname, label in items:
226 ui.write(('%s\n') % colorname, label=label) 226 ui.write(('%s\n') % colorname, label=label)
227 finally: 227 finally:
228 color._styles.clear() 228 ui._styles.clear()
229 color._styles.update(oldstyle) 229 ui._styles.update(oldstyle)
230 230
231 def _debugdisplaystyle(ui): 231 def _debugdisplaystyle(ui):
232 ui.write(_('available style:\n')) 232 ui.write(_('available style:\n'))
233 width = max(len(s) for s in color._styles) 233 width = max(len(s) for s in ui._styles)
234 for label, effects in sorted(color._styles.items()): 234 for label, effects in sorted(ui._styles.items()):
235 ui.write('%s' % label, label=label) 235 ui.write('%s' % label, label=label)
236 if effects: 236 if effects:
237 # 50 237 # 50
238 ui.write(': ') 238 ui.write(': ')
239 ui.write(' ' * (max(0, width - len(label)))) 239 ui.write(' ' * (max(0, width - len(label))))