Patchwork color: omit terminfo/win32 warning if non-interactive (issue4543)

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date March 10, 2015, 5:45 p.m.
Message ID <5efb14174207f3d8cd46.1426009555@Iris>
Download mbox | patch
Permalink /patch/7969/
State Superseded
Commit 5058e6962fcca9194ca78a5436902513168437e9
Headers show

Comments

Jordi Gutiérrez Hermoso - March 10, 2015, 5:45 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1426009214 14400
#      Tue Mar 10 13:40:14 2015 -0400
# Node ID 5efb14174207f3d8cd4643665c0277ce061692ce
# Parent  02d7b5cd373bbb4e8263dad9bfbf9c4c3b0e4e3a
color: omit terminfo/win32 warning if non-interactive (issue4543)

It's pretty annoying to be getting this warning when already the
colour extension has no hope of working. If there isn't a human on the
other end to to see the colours, there probably isn't a human either
who cares about this warning. More likely, some script somewhere is
gonna get confused with the warning output.

Of course, if we still want to see the warning for some reason, we can
always set --config ui.interactive=True.
Jordi Gutiérrez Hermoso - March 10, 2015, 7:54 p.m.
On Tue, 2015-03-10 at 13:45 -0400, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1426009214 14400
> #      Tue Mar 10 13:40:14 2015 -0400
> # Node ID 5efb14174207f3d8cd4643665c0277ce061692ce
> # Parent  02d7b5cd373bbb4e8263dad9bfbf9c4c3b0e4e3a
> color: omit terminfo/win32 warning if non-interactive (issue4543)
[snip]
> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -254,7 +254,7 @@ def _modesetup(ui, coloropt):
>      if realmode == 'win32':
>          _terminfo_params = {}
>          if not w32effects:
> -            if mode == 'win32':
> +            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)
>              return None
> @@ -264,7 +264,7 @@ def _modesetup(ui, coloropt):
>      elif realmode == 'terminfo':
>          _terminfosetup(ui, mode)
>          if not _terminfo_params:
> -            if mode == 'terminfo':
> +            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)

While I was looking at this code, I see that there's some mild case of
C&P code here since ad6ad51cc0dd. I'm preparing a V2 that obsoletes
this change and gets rid of the C&P.
Matt Mackall - March 10, 2015, 8:30 p.m.
On Tue, 2015-03-10 at 13:45 -0400, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1426009214 14400
> #      Tue Mar 10 13:40:14 2015 -0400
> # Node ID 5efb14174207f3d8cd4643665c0277ce061692ce
> # Parent  02d7b5cd373bbb4e8263dad9bfbf9c4c3b0e4e3a
> color: omit terminfo/win32 warning if non-interactive (issue4543)

Queued for default, thanks.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -254,7 +254,7 @@  def _modesetup(ui, coloropt):
     if realmode == 'win32':
         _terminfo_params = {}
         if not w32effects:
-            if mode == 'win32':
+            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)
             return None
@@ -264,7 +264,7 @@  def _modesetup(ui, coloropt):
     elif realmode == 'terminfo':
         _terminfosetup(ui, mode)
         if not _terminfo_params:
-            if mode == 'terminfo':
+            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)