comparison hgext/color.py @ 24266:c14b1d349af3

color: consolidate cut-and-paste code This fixes a mild case of cut-and-paste code regarding failing to set terminal modes. This is evident in the win32 comment that is misplaced for the terminfo mode since cset ad6ad51cc0dd. Instead, we refactor this C&P into a small local function.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Wed, 11 Mar 2015 09:34:22 -0400
parents 5058e6962fcc
children 1818d4dca75c
comparison
equal deleted inserted replaced
24265:dc655360bccb 24266:c14b1d349af3
249 else: 249 else:
250 realmode = 'win32' 250 realmode = 'win32'
251 else: 251 else:
252 realmode = 'ansi' 252 realmode = 'ansi'
253 253
254 def modewarn():
255 # only warn if color.mode was explicitly set and we're in
256 # an interactive terminal
257 if mode == realmode and ui.interactive():
258 ui.warn(_('warning: failed to set color mode to %s\n') % mode)
259
254 if realmode == 'win32': 260 if realmode == 'win32':
255 _terminfo_params = {} 261 _terminfo_params = {}
256 if not w32effects: 262 if not w32effects:
257 if mode == 'win32' and ui.interactive(): 263 modewarn()
258 # only warn if color.mode is explicitly set to win32
259 ui.warn(_('warning: failed to set color mode to %s\n') % mode)
260 return None 264 return None
261 _effects.update(w32effects) 265 _effects.update(w32effects)
262 elif realmode == 'ansi': 266 elif realmode == 'ansi':
263 _terminfo_params = {} 267 _terminfo_params = {}
264 elif realmode == 'terminfo': 268 elif realmode == 'terminfo':
265 _terminfosetup(ui, mode) 269 _terminfosetup(ui, mode)
266 if not _terminfo_params: 270 if not _terminfo_params:
267 if mode == 'terminfo' and ui.interactive(): 271 ## FIXME Shouldn't we return None in this case too?
268 ## FIXME Shouldn't we return None in this case too? 272 modewarn()
269 # only warn if color.mode is explicitly set to win32
270 ui.warn(_('warning: failed to set color mode to %s\n') % mode)
271 realmode = 'ansi' 273 realmode = 'ansi'
272 else: 274 else:
273 return None 275 return None
274 276
275 if always or (auto and formatted): 277 if always or (auto and formatted):