Patchwork color: show mode warning based on ui.formatted

login
register
mail settings
Submitter Xidorn Quan
Date Nov. 11, 2016, 3:19 a.m.
Message ID <1ffdeb65f19e74ea211a.1478834382@upsuper-mbp2.local>
Download mbox | patch
Permalink /patch/17468/
State Accepted
Headers show

Comments

Xidorn Quan - Nov. 11, 2016, 3:19 a.m.
# HG changeset patch
# User Xidorn Quan <me@upsuper.org>
# Date 1478829965 -39600
#      Fri Nov 11 13:06:05 2016 +1100
# Node ID 1ffdeb65f19e74ea211af4d9f7c9c4c1dfaa7069
# Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
color: show mode warning based on ui.formatted
Sean Farley - Nov. 11, 2016, 4:36 a.m.
Xidorn Quan <me@upsuper.org> writes:

> # HG changeset patch
> # User Xidorn Quan <me@upsuper.org>
> # Date 1478829965 -39600
> #      Fri Nov 11 13:06:05 2016 +1100
> # Node ID 1ffdeb65f19e74ea211af4d9f7c9c4c1dfaa7069
> # Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
> color: show mode warning based on ui.formatted
>
> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -270,18 +270,18 @@ def _modesetup(ui, coloropt):
>                  realmode = 'ansi'
>              else:
>                  realmode = 'win32'
>          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():
> +        # a formatted terminal
> +        if mode == realmode and ui.formatted():

Today I learned that ui.interactive is only for input and ui.formatted
is for ouput:

"This [interactive] function refers to input only; for output, see
`ui.formatted()'."

The patch looks good to me (maybe add some explanation to the commit
message but that shouldn't require a resend).
Yuya Nishihara - Nov. 11, 2016, 2:12 p.m.
On Thu, 10 Nov 2016 20:36:25 -0800, Sean Farley wrote:
> Xidorn Quan <me@upsuper.org> writes:
> > # HG changeset patch
> > # User Xidorn Quan <me@upsuper.org>
> > # Date 1478829965 -39600
> > #      Fri Nov 11 13:06:05 2016 +1100
> > # Node ID 1ffdeb65f19e74ea211af4d9f7c9c4c1dfaa7069
> > # Parent  e1d6aa0e4c3aed73e0dc523b8a8fd5f9fe23510a
> > color: show mode warning based on ui.formatted

LGTM, too. Queued, thanks.

> Today I learned that ui.interactive is only for input and ui.formatted
> is for ouput:
> 
> "This [interactive] function refers to input only; for output, see
> `ui.formatted()'."
> 
> The patch looks good to me (maybe add some explanation to the commit
> message but that shouldn't require a resend).

Copy-edited the commit message to include "ui.interactive is only for input..."

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -270,18 +270,18 @@  def _modesetup(ui, coloropt):
                 realmode = 'ansi'
             else:
                 realmode = 'win32'
         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():
+        # a formatted terminal
+        if mode == realmode and ui.formatted():
             ui.warn(_('warning: failed to set color mode to %s\n') % mode)
 
     if realmode == 'win32':
         _terminfo_params = {}
         if not w32effects:
             modewarn()
             return None
         _effects.update(w32effects)