crecord: honor "ui.color = no" config option
authorElmar Bartel <elb_hg@leo.org>
Thu, 04 Jan 2018 12:12:07 +0100
changeset 35531 f43dc62cfe11
parent 35530 e8f80529abeb
child 35532 fb2e59e92651
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.
mercurial/crecord.py
--- 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: