comparison 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
comparison
equal deleted inserted replaced
31109:53230c5bb273 31110:7fec37746417
40 'white': (False, curses.COLOR_WHITE, ''), 40 'white': (False, curses.COLOR_WHITE, ''),
41 } 41 }
42 except ImportError: 42 except ImportError:
43 curses = None 43 curses = None
44 _terminfo_params = {} 44 _terminfo_params = {}
45
46 # allow the extensions to change the default
47 _enabledbydefault = False
45 48
46 # start and stop parameters for effects 49 # start and stop parameters for effects
47 _effects = { 50 _effects = {
48 'none': 0, 51 'none': 0,
49 'black': 30, 52 'black': 30,
165 if mode == "terminfo": 168 if mode == "terminfo":
166 ui.warn(_("no terminfo entry for setab/setaf: reverting to " 169 ui.warn(_("no terminfo entry for setab/setaf: reverting to "
167 "ECMA-48 color\n")) 170 "ECMA-48 color\n"))
168 _terminfo_params.clear() 171 _terminfo_params.clear()
169 172
170 def setup(ui, coloropts): 173 def setup(ui):
171 """configure color on a ui 174 """configure color on a ui
172 175
173 The 'coloropts' argument is the value of the '--color' command line 176 That function both set the colormode for the ui object and read
174 argument. That function both set the colormode for the ui object and read
175 the configuration looking for custom colors and effect definitions.""" 177 the configuration looking for custom colors and effect definitions."""
176 mode = _modesetup(ui, coloropts) 178 mode = _modesetup(ui)
177 ui._colormode = mode 179 ui._colormode = mode
178 if mode and mode != 'debug': 180 if mode and mode != 'debug':
179 configstyles(ui) 181 configstyles(ui)
180 182
181 def _modesetup(ui, coloropt): 183 def _modesetup(ui):
182 if ui.plain(): 184 if ui.plain():
183 return None 185 return None
184 if coloropt == 'debug': 186 default = 'never'
187 if _enabledbydefault:
188 default = 'auto'
189 # experimental config: ui.color
190 config = ui.config('ui', 'color', default)
191 if config == 'debug':
185 return 'debug' 192 return 'debug'
186 193
187 auto = (coloropt == 'auto') 194 auto = (config == 'auto')
188 always = not auto and util.parsebool(coloropt) 195 always = not auto and util.parsebool(config)
189 if not always and not auto: 196 if not always and not auto:
190 return None 197 return None
191 198
192 formatted = (always or (encoding.environ.get('TERM') != 'dumb' 199 formatted = (always or (encoding.environ.get('TERM') != 'dumb'
193 and ui.formatted())) 200 and ui.formatted()))