Mercurial > hg-stable
changeset 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 | dc655360bccb |
children | 365fdbc54f1f |
files | hgext/color.py |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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