changeset 35527:f43dc62cfe11

crecord: honor "ui.color = no" config option The current implementation of crecord ignores the ui.color setting. This patch checks the ui.color config option and does the curses setup without colors when the option is set to a falsy value. For other (or missing) setting of ui.color, curses setup is done as before and uses colors.
author Elmar Bartel <elb_hg@leo.org>
date Thu, 04 Jan 2018 12:12:07 +0100
parents e8f80529abeb
children fb2e59e92651
files mercurial/crecord.py
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/crecord.py	Tue Jan 02 21:46:57 2018 -0500
+++ b/mercurial/crecord.py	Thu Jan 04 12:12:07 2018 +0100
@@ -581,6 +581,13 @@
         # maps custom nicknames of color-pairs to curses color-pair values
         self.colorpairnames = {}
 
+        # Honor color setting of ui section. Keep colored setup as
+        # long as not explicitly set to a falsy value - especially,
+        # when not set at all. This is to stay most compatible with
+        # previous (color only) behaviour.
+        uicolor = util.parsebool(self.ui.config('ui', 'color'))
+        self.usecolor = uicolor is not False
+
         # the currently selected header, hunk, or hunk-line
         self.currentselecteditem = self.headerlist[0]
 
@@ -1371,11 +1378,19 @@
                 colorpair = self.colorpairs[(fgcolor, bgcolor)]
             else:
                 pairindex = len(self.colorpairs) + 1
-                curses.init_pair(pairindex, fgcolor, bgcolor)
-                colorpair = self.colorpairs[(fgcolor, bgcolor)] = (
-                    curses.color_pair(pairindex))
-                if name is not None:
-                    self.colorpairnames[name] = curses.color_pair(pairindex)
+                if self.usecolor:
+                    curses.init_pair(pairindex, fgcolor, bgcolor)
+                    colorpair = self.colorpairs[(fgcolor, bgcolor)] = (
+                        curses.color_pair(pairindex))
+                    if name is not None:
+                        self.colorpairnames[name] = curses.color_pair(pairindex)
+                else:
+                    cval = 0
+                    if name is not None:
+                        if name == 'selected':
+                            cval = curses.A_REVERSE
+                        self.colorpairnames[name] = cval
+                    colorpair = self.colorpairs[(fgcolor, bgcolor)] = cval
 
         # add attributes if possible
         if attrlist is None: