##// END OF EJS Templates
color: drop the 'colorui' class...
Pierre-Yves David -
r31095:b4cb86ab default
parent child Browse files
Show More
@@ -1,374 +1,368 b''
1 # color.py color output for Mercurial commands
1 # color.py color output for Mercurial commands
2 #
2 #
3 # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com>
3 # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 '''colorize output from some commands
8 '''colorize output from some commands
9
9
10 The color extension colorizes output from several Mercurial commands.
10 The color extension colorizes output from several Mercurial commands.
11 For example, the diff command shows additions in green and deletions
11 For example, the diff command shows additions in green and deletions
12 in red, while the status command shows modified files in magenta. Many
12 in red, while the status command shows modified files in magenta. Many
13 other commands have analogous colors. It is possible to customize
13 other commands have analogous colors. It is possible to customize
14 these colors.
14 these colors.
15
15
16 Effects
16 Effects
17 -------
17 -------
18
18
19 Other effects in addition to color, like bold and underlined text, are
19 Other effects in addition to color, like bold and underlined text, are
20 also available. By default, the terminfo database is used to find the
20 also available. By default, the terminfo database is used to find the
21 terminal codes used to change color and effect. If terminfo is not
21 terminal codes used to change color and effect. If terminfo is not
22 available, then effects are rendered with the ECMA-48 SGR control
22 available, then effects are rendered with the ECMA-48 SGR control
23 function (aka ANSI escape codes).
23 function (aka ANSI escape codes).
24
24
25 The available effects in terminfo mode are 'blink', 'bold', 'dim',
25 The available effects in terminfo mode are 'blink', 'bold', 'dim',
26 'inverse', 'invisible', 'italic', 'standout', and 'underline'; in
26 'inverse', 'invisible', 'italic', 'standout', and 'underline'; in
27 ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and
27 ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and
28 'underline'. How each is rendered depends on the terminal emulator.
28 'underline'. How each is rendered depends on the terminal emulator.
29 Some may not be available for a given terminal type, and will be
29 Some may not be available for a given terminal type, and will be
30 silently ignored.
30 silently ignored.
31
31
32 If the terminfo entry for your terminal is missing codes for an effect
32 If the terminfo entry for your terminal is missing codes for an effect
33 or has the wrong codes, you can add or override those codes in your
33 or has the wrong codes, you can add or override those codes in your
34 configuration::
34 configuration::
35
35
36 [color]
36 [color]
37 terminfo.dim = \E[2m
37 terminfo.dim = \E[2m
38
38
39 where '\E' is substituted with an escape character.
39 where '\E' is substituted with an escape character.
40
40
41 Labels
41 Labels
42 ------
42 ------
43
43
44 Text receives color effects depending on the labels that it has. Many
44 Text receives color effects depending on the labels that it has. Many
45 default Mercurial commands emit labelled text. You can also define
45 default Mercurial commands emit labelled text. You can also define
46 your own labels in templates using the label function, see :hg:`help
46 your own labels in templates using the label function, see :hg:`help
47 templates`. A single portion of text may have more than one label. In
47 templates`. A single portion of text may have more than one label. In
48 that case, effects given to the last label will override any other
48 that case, effects given to the last label will override any other
49 effects. This includes the special "none" effect, which nullifies
49 effects. This includes the special "none" effect, which nullifies
50 other effects.
50 other effects.
51
51
52 Labels are normally invisible. In order to see these labels and their
52 Labels are normally invisible. In order to see these labels and their
53 position in the text, use the global --color=debug option. The same
53 position in the text, use the global --color=debug option. The same
54 anchor text may be associated to multiple labels, e.g.
54 anchor text may be associated to multiple labels, e.g.
55
55
56 [log.changeset changeset.secret|changeset: 22611:6f0a53c8f587]
56 [log.changeset changeset.secret|changeset: 22611:6f0a53c8f587]
57
57
58 The following are the default effects for some default labels. Default
58 The following are the default effects for some default labels. Default
59 effects may be overridden from your configuration file::
59 effects may be overridden from your configuration file::
60
60
61 [color]
61 [color]
62 status.modified = blue bold underline red_background
62 status.modified = blue bold underline red_background
63 status.added = green bold
63 status.added = green bold
64 status.removed = red bold blue_background
64 status.removed = red bold blue_background
65 status.deleted = cyan bold underline
65 status.deleted = cyan bold underline
66 status.unknown = magenta bold underline
66 status.unknown = magenta bold underline
67 status.ignored = black bold
67 status.ignored = black bold
68
68
69 # 'none' turns off all effects
69 # 'none' turns off all effects
70 status.clean = none
70 status.clean = none
71 status.copied = none
71 status.copied = none
72
72
73 qseries.applied = blue bold underline
73 qseries.applied = blue bold underline
74 qseries.unapplied = black bold
74 qseries.unapplied = black bold
75 qseries.missing = red bold
75 qseries.missing = red bold
76
76
77 diff.diffline = bold
77 diff.diffline = bold
78 diff.extended = cyan bold
78 diff.extended = cyan bold
79 diff.file_a = red bold
79 diff.file_a = red bold
80 diff.file_b = green bold
80 diff.file_b = green bold
81 diff.hunk = magenta
81 diff.hunk = magenta
82 diff.deleted = red
82 diff.deleted = red
83 diff.inserted = green
83 diff.inserted = green
84 diff.changed = white
84 diff.changed = white
85 diff.tab =
85 diff.tab =
86 diff.trailingwhitespace = bold red_background
86 diff.trailingwhitespace = bold red_background
87
87
88 # Blank so it inherits the style of the surrounding label
88 # Blank so it inherits the style of the surrounding label
89 changeset.public =
89 changeset.public =
90 changeset.draft =
90 changeset.draft =
91 changeset.secret =
91 changeset.secret =
92
92
93 resolve.unresolved = red bold
93 resolve.unresolved = red bold
94 resolve.resolved = green bold
94 resolve.resolved = green bold
95
95
96 bookmarks.active = green
96 bookmarks.active = green
97
97
98 branches.active = none
98 branches.active = none
99 branches.closed = black bold
99 branches.closed = black bold
100 branches.current = green
100 branches.current = green
101 branches.inactive = none
101 branches.inactive = none
102
102
103 tags.normal = green
103 tags.normal = green
104 tags.local = black bold
104 tags.local = black bold
105
105
106 rebase.rebased = blue
106 rebase.rebased = blue
107 rebase.remaining = red bold
107 rebase.remaining = red bold
108
108
109 shelve.age = cyan
109 shelve.age = cyan
110 shelve.newest = green bold
110 shelve.newest = green bold
111 shelve.name = blue bold
111 shelve.name = blue bold
112
112
113 histedit.remaining = red bold
113 histedit.remaining = red bold
114
114
115 Custom colors
115 Custom colors
116 -------------
116 -------------
117
117
118 Because there are only eight standard colors, this module allows you
118 Because there are only eight standard colors, this module allows you
119 to define color names for other color slots which might be available
119 to define color names for other color slots which might be available
120 for your terminal type, assuming terminfo mode. For instance::
120 for your terminal type, assuming terminfo mode. For instance::
121
121
122 color.brightblue = 12
122 color.brightblue = 12
123 color.pink = 207
123 color.pink = 207
124 color.orange = 202
124 color.orange = 202
125
125
126 to set 'brightblue' to color slot 12 (useful for 16 color terminals
126 to set 'brightblue' to color slot 12 (useful for 16 color terminals
127 that have brighter colors defined in the upper eight) and, 'pink' and
127 that have brighter colors defined in the upper eight) and, 'pink' and
128 'orange' to colors in 256-color xterm's default color cube. These
128 'orange' to colors in 256-color xterm's default color cube. These
129 defined colors may then be used as any of the pre-defined eight,
129 defined colors may then be used as any of the pre-defined eight,
130 including appending '_background' to set the background to that color.
130 including appending '_background' to set the background to that color.
131
131
132 Modes
132 Modes
133 -----
133 -----
134
134
135 By default, the color extension will use ANSI mode (or win32 mode on
135 By default, the color extension will use ANSI mode (or win32 mode on
136 Windows) if it detects a terminal. To override auto mode (to enable
136 Windows) if it detects a terminal. To override auto mode (to enable
137 terminfo mode, for example), set the following configuration option::
137 terminfo mode, for example), set the following configuration option::
138
138
139 [color]
139 [color]
140 mode = terminfo
140 mode = terminfo
141
141
142 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will
142 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will
143 disable color.
143 disable color.
144
144
145 Note that on some systems, terminfo mode may cause problems when using
145 Note that on some systems, terminfo mode may cause problems when using
146 color with the pager extension and less -R. less with the -R option
146 color with the pager extension and less -R. less with the -R option
147 will only display ECMA-48 color codes, and terminfo mode may sometimes
147 will only display ECMA-48 color codes, and terminfo mode may sometimes
148 emit codes that less doesn't understand. You can work around this by
148 emit codes that less doesn't understand. You can work around this by
149 either using ansi mode (or auto mode), or by using less -r (which will
149 either using ansi mode (or auto mode), or by using less -r (which will
150 pass through all terminal control codes, not just color control
150 pass through all terminal control codes, not just color control
151 codes).
151 codes).
152
152
153 On some systems (such as MSYS in Windows), the terminal may support
153 On some systems (such as MSYS in Windows), the terminal may support
154 a different color mode than the pager (activated via the "pager"
154 a different color mode than the pager (activated via the "pager"
155 extension). It is possible to define separate modes depending on whether
155 extension). It is possible to define separate modes depending on whether
156 the pager is active::
156 the pager is active::
157
157
158 [color]
158 [color]
159 mode = auto
159 mode = auto
160 pagermode = ansi
160 pagermode = ansi
161
161
162 If ``pagermode`` is not defined, the ``mode`` will be used.
162 If ``pagermode`` is not defined, the ``mode`` will be used.
163 '''
163 '''
164
164
165 from __future__ import absolute_import
165 from __future__ import absolute_import
166
166
167 try:
167 try:
168 import curses
168 import curses
169 curses.COLOR_BLACK # force import
169 curses.COLOR_BLACK # force import
170 except ImportError:
170 except ImportError:
171 curses = None
171 curses = None
172
172
173 from mercurial.i18n import _
173 from mercurial.i18n import _
174 from mercurial import (
174 from mercurial import (
175 cmdutil,
175 cmdutil,
176 color,
176 color,
177 commands,
177 commands,
178 dispatch,
178 dispatch,
179 encoding,
179 encoding,
180 extensions,
180 extensions,
181 pycompat,
181 pycompat,
182 subrepo,
182 subrepo,
183 ui as uimod,
183 ui as uimod,
184 util,
184 util,
185 )
185 )
186
186
187 cmdtable = {}
187 cmdtable = {}
188 command = cmdutil.command(cmdtable)
188 command = cmdutil.command(cmdtable)
189 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
189 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
190 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
190 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
191 # be specifying the version(s) of Mercurial they are tested with, or
191 # be specifying the version(s) of Mercurial they are tested with, or
192 # leave the attribute unspecified.
192 # leave the attribute unspecified.
193 testedwith = 'ships-with-hg-core'
193 testedwith = 'ships-with-hg-core'
194
194
195 def _terminfosetup(ui, mode):
195 def _terminfosetup(ui, mode):
196 '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
196 '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
197
197
198 # If we failed to load curses, we go ahead and return.
198 # If we failed to load curses, we go ahead and return.
199 if curses is None:
199 if curses is None:
200 return
200 return
201 # Otherwise, see what the config file says.
201 # Otherwise, see what the config file says.
202 if mode not in ('auto', 'terminfo'):
202 if mode not in ('auto', 'terminfo'):
203 return
203 return
204
204
205 for key, val in ui.configitems('color'):
205 for key, val in ui.configitems('color'):
206 if key.startswith('color.'):
206 if key.startswith('color.'):
207 newval = (False, int(val), '')
207 newval = (False, int(val), '')
208 color._terminfo_params[key[6:]] = newval
208 color._terminfo_params[key[6:]] = newval
209 elif key.startswith('terminfo.'):
209 elif key.startswith('terminfo.'):
210 newval = (True, '', val.replace('\\E', '\x1b'))
210 newval = (True, '', val.replace('\\E', '\x1b'))
211 color._terminfo_params[key[9:]] = newval
211 color._terminfo_params[key[9:]] = newval
212 try:
212 try:
213 curses.setupterm()
213 curses.setupterm()
214 except curses.error as e:
214 except curses.error as e:
215 color._terminfo_params.clear()
215 color._terminfo_params.clear()
216 return
216 return
217
217
218 for key, (b, e, c) in color._terminfo_params.items():
218 for key, (b, e, c) in color._terminfo_params.items():
219 if not b:
219 if not b:
220 continue
220 continue
221 if not c and not curses.tigetstr(e):
221 if not c and not curses.tigetstr(e):
222 # Most terminals don't support dim, invis, etc, so don't be
222 # Most terminals don't support dim, invis, etc, so don't be
223 # noisy and use ui.debug().
223 # noisy and use ui.debug().
224 ui.debug("no terminfo entry for %s\n" % e)
224 ui.debug("no terminfo entry for %s\n" % e)
225 del color._terminfo_params[key]
225 del color._terminfo_params[key]
226 if not curses.tigetstr('setaf') or not curses.tigetstr('setab'):
226 if not curses.tigetstr('setaf') or not curses.tigetstr('setab'):
227 # Only warn about missing terminfo entries if we explicitly asked for
227 # Only warn about missing terminfo entries if we explicitly asked for
228 # terminfo mode.
228 # terminfo mode.
229 if mode == "terminfo":
229 if mode == "terminfo":
230 ui.warn(_("no terminfo entry for setab/setaf: reverting to "
230 ui.warn(_("no terminfo entry for setab/setaf: reverting to "
231 "ECMA-48 color\n"))
231 "ECMA-48 color\n"))
232 color._terminfo_params.clear()
232 color._terminfo_params.clear()
233
233
234 def _modesetup(ui, coloropt):
234 def _modesetup(ui, coloropt):
235 if coloropt == 'debug':
235 if coloropt == 'debug':
236 return 'debug'
236 return 'debug'
237
237
238 auto = (coloropt == 'auto')
238 auto = (coloropt == 'auto')
239 always = not auto and util.parsebool(coloropt)
239 always = not auto and util.parsebool(coloropt)
240 if not always and not auto:
240 if not always and not auto:
241 return None
241 return None
242
242
243 formatted = (always or (encoding.environ.get('TERM') != 'dumb'
243 formatted = (always or (encoding.environ.get('TERM') != 'dumb'
244 and ui.formatted()))
244 and ui.formatted()))
245
245
246 mode = ui.config('color', 'mode', 'auto')
246 mode = ui.config('color', 'mode', 'auto')
247
247
248 # If pager is active, color.pagermode overrides color.mode.
248 # If pager is active, color.pagermode overrides color.mode.
249 if getattr(ui, 'pageractive', False):
249 if getattr(ui, 'pageractive', False):
250 mode = ui.config('color', 'pagermode', mode)
250 mode = ui.config('color', 'pagermode', mode)
251
251
252 realmode = mode
252 realmode = mode
253 if mode == 'auto':
253 if mode == 'auto':
254 if pycompat.osname == 'nt':
254 if pycompat.osname == 'nt':
255 term = encoding.environ.get('TERM')
255 term = encoding.environ.get('TERM')
256 # TERM won't be defined in a vanilla cmd.exe environment.
256 # TERM won't be defined in a vanilla cmd.exe environment.
257
257
258 # UNIX-like environments on Windows such as Cygwin and MSYS will
258 # UNIX-like environments on Windows such as Cygwin and MSYS will
259 # set TERM. They appear to make a best effort attempt at setting it
259 # set TERM. They appear to make a best effort attempt at setting it
260 # to something appropriate. However, not all environments with TERM
260 # to something appropriate. However, not all environments with TERM
261 # defined support ANSI. Since "ansi" could result in terminal
261 # defined support ANSI. Since "ansi" could result in terminal
262 # gibberish, we error on the side of selecting "win32". However, if
262 # gibberish, we error on the side of selecting "win32". However, if
263 # w32effects is not defined, we almost certainly don't support
263 # w32effects is not defined, we almost certainly don't support
264 # "win32", so don't even try.
264 # "win32", so don't even try.
265 if (term and 'xterm' in term) or not color.w32effects:
265 if (term and 'xterm' in term) or not color.w32effects:
266 realmode = 'ansi'
266 realmode = 'ansi'
267 else:
267 else:
268 realmode = 'win32'
268 realmode = 'win32'
269 else:
269 else:
270 realmode = 'ansi'
270 realmode = 'ansi'
271
271
272 def modewarn():
272 def modewarn():
273 # only warn if color.mode was explicitly set and we're in
273 # only warn if color.mode was explicitly set and we're in
274 # a formatted terminal
274 # a formatted terminal
275 if mode == realmode and ui.formatted():
275 if mode == realmode and ui.formatted():
276 ui.warn(_('warning: failed to set color mode to %s\n') % mode)
276 ui.warn(_('warning: failed to set color mode to %s\n') % mode)
277
277
278 if realmode == 'win32':
278 if realmode == 'win32':
279 color._terminfo_params.clear()
279 color._terminfo_params.clear()
280 if not color.w32effects:
280 if not color.w32effects:
281 modewarn()
281 modewarn()
282 return None
282 return None
283 color._effects.update(color.w32effects)
283 color._effects.update(color.w32effects)
284 elif realmode == 'ansi':
284 elif realmode == 'ansi':
285 color._terminfo_params.clear()
285 color._terminfo_params.clear()
286 elif realmode == 'terminfo':
286 elif realmode == 'terminfo':
287 _terminfosetup(ui, mode)
287 _terminfosetup(ui, mode)
288 if not color._terminfo_params:
288 if not color._terminfo_params:
289 ## FIXME Shouldn't we return None in this case too?
289 ## FIXME Shouldn't we return None in this case too?
290 modewarn()
290 modewarn()
291 realmode = 'ansi'
291 realmode = 'ansi'
292 else:
292 else:
293 return None
293 return None
294
294
295 if always or (auto and formatted):
295 if always or (auto and formatted):
296 return realmode
296 return realmode
297 return None
297 return None
298
298
299 class colorui(uimod.ui):
300 pass
301
302 def uisetup(ui):
299 def uisetup(ui):
303 if ui.plain():
300 if ui.plain():
304 return
301 return
305 if not isinstance(ui, colorui):
306 colorui.__bases__ = (ui.__class__,)
307 ui.__class__ = colorui
308 def colorcmd(orig, ui_, opts, cmd, cmdfunc):
302 def colorcmd(orig, ui_, opts, cmd, cmdfunc):
309 mode = _modesetup(ui_, opts['color'])
303 mode = _modesetup(ui_, opts['color'])
310 colorui._colormode = mode
304 uimod.ui._colormode = mode
311 if mode and mode != 'debug':
305 if mode and mode != 'debug':
312 color.configstyles(ui_)
306 color.configstyles(ui_)
313 return orig(ui_, opts, cmd, cmdfunc)
307 return orig(ui_, opts, cmd, cmdfunc)
314 def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
308 def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
315 if gitsub.ui._colormode and len(commands) and commands[0] == "diff":
309 if gitsub.ui._colormode and len(commands) and commands[0] == "diff":
316 # insert the argument in the front,
310 # insert the argument in the front,
317 # the end of git diff arguments is used for paths
311 # the end of git diff arguments is used for paths
318 commands.insert(1, '--color')
312 commands.insert(1, '--color')
319 return orig(gitsub, commands, env, stream, cwd)
313 return orig(gitsub, commands, env, stream, cwd)
320 extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
314 extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
321 extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit)
315 extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit)
322
316
323 def extsetup(ui):
317 def extsetup(ui):
324 commands.globalopts.append(
318 commands.globalopts.append(
325 ('', 'color', 'auto',
319 ('', 'color', 'auto',
326 # i18n: 'always', 'auto', 'never', and 'debug' are keywords
320 # i18n: 'always', 'auto', 'never', and 'debug' are keywords
327 # and should not be translated
321 # and should not be translated
328 _("when to colorize (boolean, always, auto, never, or debug)"),
322 _("when to colorize (boolean, always, auto, never, or debug)"),
329 _('TYPE')))
323 _('TYPE')))
330
324
331 @command('debugcolor',
325 @command('debugcolor',
332 [('', 'style', None, _('show all configured styles'))],
326 [('', 'style', None, _('show all configured styles'))],
333 'hg debugcolor')
327 'hg debugcolor')
334 def debugcolor(ui, repo, **opts):
328 def debugcolor(ui, repo, **opts):
335 """show available color, effects or style"""
329 """show available color, effects or style"""
336 ui.write(('color mode: %s\n') % ui._colormode)
330 ui.write(('color mode: %s\n') % ui._colormode)
337 if opts.get('style'):
331 if opts.get('style'):
338 return _debugdisplaystyle(ui)
332 return _debugdisplaystyle(ui)
339 else:
333 else:
340 return _debugdisplaycolor(ui)
334 return _debugdisplaycolor(ui)
341
335
342 def _debugdisplaycolor(ui):
336 def _debugdisplaycolor(ui):
343 oldstyle = color._styles.copy()
337 oldstyle = color._styles.copy()
344 try:
338 try:
345 color._styles.clear()
339 color._styles.clear()
346 for effect in color._effects.keys():
340 for effect in color._effects.keys():
347 color._styles[effect] = effect
341 color._styles[effect] = effect
348 if color._terminfo_params:
342 if color._terminfo_params:
349 for k, v in ui.configitems('color'):
343 for k, v in ui.configitems('color'):
350 if k.startswith('color.'):
344 if k.startswith('color.'):
351 color._styles[k] = k[6:]
345 color._styles[k] = k[6:]
352 elif k.startswith('terminfo.'):
346 elif k.startswith('terminfo.'):
353 color._styles[k] = k[9:]
347 color._styles[k] = k[9:]
354 ui.write(_('available colors:\n'))
348 ui.write(_('available colors:\n'))
355 # sort label with a '_' after the other to group '_background' entry.
349 # sort label with a '_' after the other to group '_background' entry.
356 items = sorted(color._styles.items(),
350 items = sorted(color._styles.items(),
357 key=lambda i: ('_' in i[0], i[0], i[1]))
351 key=lambda i: ('_' in i[0], i[0], i[1]))
358 for colorname, label in items:
352 for colorname, label in items:
359 ui.write(('%s\n') % colorname, label=label)
353 ui.write(('%s\n') % colorname, label=label)
360 finally:
354 finally:
361 color._styles.clear()
355 color._styles.clear()
362 color._styles.update(oldstyle)
356 color._styles.update(oldstyle)
363
357
364 def _debugdisplaystyle(ui):
358 def _debugdisplaystyle(ui):
365 ui.write(_('available style:\n'))
359 ui.write(_('available style:\n'))
366 width = max(len(s) for s in color._styles)
360 width = max(len(s) for s in color._styles)
367 for label, effects in sorted(color._styles.items()):
361 for label, effects in sorted(color._styles.items()):
368 ui.write('%s' % label, label=label)
362 ui.write('%s' % label, label=label)
369 if effects:
363 if effects:
370 # 50
364 # 50
371 ui.write(': ')
365 ui.write(': ')
372 ui.write(' ' * (max(0, width - len(label))))
366 ui.write(' ' * (max(0, width - len(label))))
373 ui.write(', '.join(ui.label(e, e) for e in effects.split()))
367 ui.write(', '.join(ui.label(e, e) for e in effects.split()))
374 ui.write('\n')
368 ui.write('\n')
@@ -1,40 +1,38 b''
1 from __future__ import absolute_import, print_function
1 from __future__ import absolute_import, print_function
2
2
3 import os
3 import os
4 from hgext import (
5 color,
6 )
7 from mercurial import (
4 from mercurial import (
8 dispatch,
5 dispatch,
9 ui as uimod,
6 ui as uimod,
10 )
7 )
11
8
12 # ensure errors aren't buffered
9 # ensure errors aren't buffered
13 testui = color.colorui()
10 testui = uimod.ui()
14 testui.pushbuffer()
11 testui.pushbuffer()
15 testui.write(('buffered\n'))
12 testui.write(('buffered\n'))
16 testui.warn(('warning\n'))
13 testui.warn(('warning\n'))
17 testui.write_err('error\n')
14 testui.write_err('error\n')
18 print(repr(testui.popbuffer()))
15 print(repr(testui.popbuffer()))
19
16
20 # test dispatch.dispatch with the same ui object
17 # test dispatch.dispatch with the same ui object
21 hgrc = open(os.environ["HGRCPATH"], 'w')
18 hgrc = open(os.environ["HGRCPATH"], 'w')
22 hgrc.write('[extensions]\n')
19 hgrc.write('[extensions]\n')
23 hgrc.write('color=\n')
20 hgrc.write('color=\n')
24 hgrc.close()
21 hgrc.close()
25
22
26 ui_ = uimod.ui.load()
23 ui_ = uimod.ui.load()
27 ui_.setconfig('ui', 'formatted', 'True')
24 ui_.setconfig('ui', 'formatted', 'True')
28
25
29 # we're not interested in the output, so write that to devnull
26 # we're not interested in the output, so write that to devnull
30 ui_.fout = open(os.devnull, 'w')
27 ui_.fout = open(os.devnull, 'w')
31
28
32 # call some arbitrary command just so we go through
29 # call some arbitrary command just so we go through
33 # color's wrapped _runcommand twice.
30 # color's wrapped _runcommand twice.
34 def runcmd():
31 def runcmd():
35 dispatch.dispatch(dispatch.request(['version', '-q'], ui_))
32 dispatch.dispatch(dispatch.request(['version', '-q'], ui_))
36
33
37 runcmd()
34 runcmd()
38 print("colored? " + str(issubclass(ui_.__class__, color.colorui)))
35 print("colored? %s" % (ui_._colormode is not None))
39 runcmd()
36 runcmd()
40 print("colored? " + str(issubclass(ui_.__class__, color.colorui)))
37 print("colored? %s" % (ui_._colormode is not None))
38
General Comments 0
You need to be logged in to leave comments. Login now