[PATCH V3] color: consolidate cut-and-paste code
Augie Fackler
raf at durin42.com
Wed Mar 11 11:50:30 CDT 2015
On Wed, Mar 11, 2015 at 09:51:50AM -0400, Jordi GutiƩrrez Hermoso wrote:
> # HG changeset patch
> # User Jordi GutiƩrrez Hermoso <jordigh at octave.org>
> # Date 1426080862 14400
> # Wed Mar 11 09:34:22 2015 -0400
> # Node ID b988792457a86c797e1475dcb1ae1cb4d1d24a22
> # Parent 60c279ab7bd3bb08779cd6c74230d6739a63ebea
> color: consolidate cut-and-paste code
Queued, thanks
>
> 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 --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -251,12 +251,16 @@ def _modesetup(ui, coloropt):
> 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 @@ def _modesetup(ui, coloropt):
> 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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list