Patchwork D223: color: remove warnings if term is not formatted (==dumb or !ui.formatted())

login
register
mail settings
Submitter phabricator
Date Aug. 3, 2017, 8:02 p.m.
Message ID <differential-rev-PHID-DREV-d7umv2egvnnayibsbpwy-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/22661/
State Superseded
Headers show

Comments

phabricator - Aug. 3, 2017, 8:02 p.m.
spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  If the user sets color.mode=terminfo, and then runs in the shell inside of emacs
  (so TERM=dumb), the previous behavior was that it would warn about no terminfo
  entry for setab/setaf, and then warn about 'failed to set color mode to
  terminfo'.  The first warning is silenced by carrying 'formatted' through to
  _terminfosetup, the second is silenced by using 'formatted' instead of
  ui.formatted().
  
  If --color=on (or ui.color=always) is specified, this will still warn, since the
  formatted boolean is set to true in these cases.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D223

AFFECTED FILES
  mercurial/color.py

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: mercurial-devel
phabricator - Aug. 4, 2017, 1:23 p.m.
yuja accepted this revision as: yuja.
yuja added a comment.


  Makes sense.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D223

To: spectral, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -130,7 +130,7 @@ 
 def loadcolortable(ui, extname, colortable):
     _defaultstyles.update(colortable)
 
-def _terminfosetup(ui, mode):
+def _terminfosetup(ui, mode, formatted):
     '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
 
     # If we failed to load curses, we go ahead and return.
@@ -164,8 +164,8 @@ 
             del ui._terminfoparams[key]
     if not curses.tigetstr('setaf') or not curses.tigetstr('setab'):
         # Only warn about missing terminfo entries if we explicitly asked for
-        # terminfo mode.
-        if mode == "terminfo":
+        # terminfo mode and we're in a formatted terminal.
+        if mode == "terminfo" and formatted:
             ui.warn(_("no terminfo entry for setab/setaf: reverting to "
               "ECMA-48 color\n"))
         ui._terminfoparams.clear()
@@ -242,7 +242,7 @@ 
     def modewarn():
         # only warn if color.mode was explicitly set and we're in
         # a formatted terminal
-        if mode == realmode and ui.formatted():
+        if mode == realmode and formatted:
             ui.warn(_('warning: failed to set color mode to %s\n') % mode)
 
     if realmode == 'win32':
@@ -253,7 +253,7 @@ 
     elif realmode == 'ansi':
         ui._terminfoparams.clear()
     elif realmode == 'terminfo':
-        _terminfosetup(ui, mode)
+        _terminfosetup(ui, mode, formatted)
         if not ui._terminfoparams:
             ## FIXME Shouldn't we return None in this case too?
             modewarn()