diff mercurial/color.py @ 31110:7fec37746417

color: add a 'ui.color' option to control color behavior This new option control whether or not color will be used. It mirror the behavior of '--color'. I usually avoid adding new option to '[ui]' as the section is already filled with many option. However, I feel like 'color' is central enough to deserves a spot in this '[ui]' section. For now the option is not documented so it is still marked as experimental. Once it get documented and official, we should be able to deprecate the color extensions. There is more cleanup to do before that documentation is written, but we need this option early to made them. Having that option will allow for more cleanup of the initialisation process and proper separation between color configuration.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 25 Feb 2017 19:44:23 +0100
parents 53230c5bb273
children 7f056fdbe37e
line wrap: on
line diff
--- a/mercurial/color.py	Tue Feb 28 11:42:07 2017 +0100
+++ b/mercurial/color.py	Sat Feb 25 19:44:23 2017 +0100
@@ -43,6 +43,9 @@
     curses = None
     _terminfo_params = {}
 
+# allow the extensions to change the default
+_enabledbydefault = False
+
 # start and stop parameters for effects
 _effects = {
     'none': 0,
@@ -167,25 +170,29 @@
               "ECMA-48 color\n"))
         _terminfo_params.clear()
 
-def setup(ui, coloropts):
+def setup(ui):
     """configure color on a ui
 
-    The 'coloropts' argument is the value of the '--color' command line
-    argument. That function both set the colormode for the ui object and read
+    That function both set the colormode for the ui object and read
     the configuration looking for custom colors and effect definitions."""
-    mode = _modesetup(ui, coloropts)
+    mode = _modesetup(ui)
     ui._colormode = mode
     if mode and mode != 'debug':
         configstyles(ui)
 
-def _modesetup(ui, coloropt):
+def _modesetup(ui):
     if ui.plain():
         return None
-    if coloropt == 'debug':
+    default = 'never'
+    if _enabledbydefault:
+        default = 'auto'
+    # experimental config: ui.color
+    config = ui.config('ui', 'color', default)
+    if config == 'debug':
         return 'debug'
 
-    auto = (coloropt == 'auto')
-    always = not auto and util.parsebool(coloropt)
+    auto = (config == 'auto')
+    always = not auto and util.parsebool(config)
     if not always and not auto:
         return None