# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1426080862 14400 # Node ID c14b1d349af31f603ffae99613f0d994cf0d8633 # Parent dc655360bccb5a5734749b30d5aad96b6c2d977b 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. diff -r dc655360bccb -r c14b1d349af3 hgext/color.py --- a/hgext/color.py Mon Mar 09 13:16:25 2015 -0700 +++ b/hgext/color.py Wed Mar 11 09:34:22 2015 -0400 @@ -251,12 +251,16 @@ else: realmode = 'ansi' + def modewarn(): + # only warn if color.mode was explicitly set and we're in + # an interactive terminal + if mode == realmode and ui.interactive(): + ui.warn(_('warning: failed to set color mode to %s\n') % mode) + if realmode == 'win32': _terminfo_params = {} if not w32effects: - if mode == 'win32' and ui.interactive(): - # only warn if color.mode is explicitly set to win32 - ui.warn(_('warning: failed to set color mode to %s\n') % mode) + modewarn() return None _effects.update(w32effects) elif realmode == 'ansi': @@ -264,10 +268,8 @@ elif realmode == 'terminfo': _terminfosetup(ui, mode) if not _terminfo_params: - if mode == 'terminfo' and ui.interactive(): - ## FIXME Shouldn't we return None in this case too? - # only warn if color.mode is explicitly set to win32 - ui.warn(_('warning: failed to set color mode to %s\n') % mode) + ## FIXME Shouldn't we return None in this case too? + modewarn() realmode = 'ansi' else: return None