diff --git a/hgext/color.py b/hgext/color.py --- a/hgext/color.py +++ b/hgext/color.py @@ -175,9 +175,6 @@ from mercurial import ( cmdutil, color, commands, - dispatch, - extensions, - ui as uimod, ) cmdtable = {} @@ -188,15 +185,6 @@ command = cmdutil.command(cmdtable) # leave the attribute unspecified. testedwith = 'ships-with-hg-core' -def uisetup(ui): - def colorcmd(orig, ui_, opts, cmd, cmdfunc): - mode = color._modesetup(ui_, opts['color']) - uimod.ui._colormode = mode - if mode and mode != 'debug': - color.configstyles(ui_) - return orig(ui_, opts, cmd, cmdfunc) - extensions.wrapfunction(dispatch, '_runcommand', colorcmd) - def extsetup(ui): # change default color config for idx, entry in enumerate(commands.globalopts): diff --git a/mercurial/color.py b/mercurial/color.py --- a/mercurial/color.py +++ b/mercurial/color.py @@ -161,6 +161,17 @@ def _terminfosetup(ui, mode): "ECMA-48 color\n")) _terminfo_params.clear() +def setup(ui, coloropts): + """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 + the configuration looking for custom colors and effect definitions.""" + mode = _modesetup(ui, coloropts) + ui.__class__._colormode = mode + if mode and mode != 'debug': + configstyles(ui) + def _modesetup(ui, coloropt): if ui.plain(): return None diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -764,6 +764,10 @@ def _dispatch(req): for ui_ in uis: ui_.insecureconnections = True + # setup color handling + for ui_ in uis: + color.setup(ui_, options['color']) + if options['version']: return commands.version_(ui) if options['help']: diff --git a/tests/test-status-color.t b/tests/test-status-color.t --- a/tests/test-status-color.t +++ b/tests/test-status-color.t @@ -295,6 +295,7 @@ test unknown color $ hg --config color.status.modified=periwinkle status --color=always ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) + ignoring unknown color/effect 'periwinkle' (configured in color.status.modified) M modified \x1b[0;32;1mA \x1b[0m\x1b[0;32;1madded\x1b[0m (esc) \x1b[0;32;1mA \x1b[0m\x1b[0;32;1mcopied\x1b[0m (esc)