[PATCH 1 of 7] color: move 'terminfosetup' into the core module

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Feb 25 13:11:33 UTC 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1482412672 -3600
#      Thu Dec 22 14:17:52 2016 +0100
# Node ID 1d52488a538cebabbbca205cd312a4dfd83418af
# Parent  b4cb86ab4c719eb615a4308eafd8b1386a511eeb
# EXP-Topic color
color: move 'terminfosetup' into the core module

Another step closer to have all the logic living in core

diff -r b4cb86ab4c71 -r 1d52488a538c hgext/color.py
--- a/hgext/color.py	Mon Feb 20 12:42:35 2017 +0100
+++ b/hgext/color.py	Thu Dec 22 14:17:52 2016 +0100
@@ -192,45 +192,6 @@ command = cmdutil.command(cmdtable)
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
-def _terminfosetup(ui, mode):
-    '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
-
-    # If we failed to load curses, we go ahead and return.
-    if curses is None:
-        return
-    # Otherwise, see what the config file says.
-    if mode not in ('auto', 'terminfo'):
-        return
-
-    for key, val in ui.configitems('color'):
-        if key.startswith('color.'):
-            newval = (False, int(val), '')
-            color._terminfo_params[key[6:]] = newval
-        elif key.startswith('terminfo.'):
-            newval = (True, '', val.replace('\\E', '\x1b'))
-            color._terminfo_params[key[9:]] = newval
-    try:
-        curses.setupterm()
-    except curses.error as e:
-        color._terminfo_params.clear()
-        return
-
-    for key, (b, e, c) in color._terminfo_params.items():
-        if not b:
-            continue
-        if not c and not curses.tigetstr(e):
-            # Most terminals don't support dim, invis, etc, so don't be
-            # noisy and use ui.debug().
-            ui.debug("no terminfo entry for %s\n" % e)
-            del color._terminfo_params[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":
-            ui.warn(_("no terminfo entry for setab/setaf: reverting to "
-              "ECMA-48 color\n"))
-        color._terminfo_params.clear()
-
 def _modesetup(ui, coloropt):
     if coloropt == 'debug':
         return 'debug'
@@ -284,7 +245,7 @@ def _modesetup(ui, coloropt):
     elif realmode == 'ansi':
         color._terminfo_params.clear()
     elif realmode == 'terminfo':
-        _terminfosetup(ui, mode)
+        color._terminfosetup(ui, mode)
         if not color._terminfo_params:
             ## FIXME Shouldn't we return None in this case too?
             modewarn()
diff -r b4cb86ab4c71 -r 1d52488a538c mercurial/color.py
--- a/mercurial/color.py	Mon Feb 20 12:42:35 2017 +0100
+++ b/mercurial/color.py	Thu Dec 22 14:17:52 2016 +0100
@@ -118,6 +118,45 @@ except ImportError:
 def loadcolortable(ui, extname, colortable):
     _styles.update(colortable)
 
+def _terminfosetup(ui, mode):
+    '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
+
+    # If we failed to load curses, we go ahead and return.
+    if curses is None:
+        return
+    # Otherwise, see what the config file says.
+    if mode not in ('auto', 'terminfo'):
+        return
+
+    for key, val in ui.configitems('color'):
+        if key.startswith('color.'):
+            newval = (False, int(val), '')
+            _terminfo_params[key[6:]] = newval
+        elif key.startswith('terminfo.'):
+            newval = (True, '', val.replace('\\E', '\x1b'))
+            _terminfo_params[key[9:]] = newval
+    try:
+        curses.setupterm()
+    except curses.error as e:
+        _terminfo_params.clear()
+        return
+
+    for key, (b, e, c) in _terminfo_params.items():
+        if not b:
+            continue
+        if not c and not curses.tigetstr(e):
+            # Most terminals don't support dim, invis, etc, so don't be
+            # noisy and use ui.debug().
+            ui.debug("no terminfo entry for %s\n" % e)
+            del _terminfo_params[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":
+            ui.warn(_("no terminfo entry for setab/setaf: reverting to "
+              "ECMA-48 color\n"))
+        _terminfo_params.clear()
+
 def configstyles(ui):
     for status, cfgeffects in ui.configitems('color'):
         if '.' not in status or status.startswith(('color.', 'terminfo.')):


More information about the Mercurial-devel mailing list