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: |
|
168 import curses |
|
169 curses.COLOR_BLACK # force import |
|
170 except ImportError: |
|
171 curses = None |
|
172 |
|
173 from mercurial.i18n import _ |
|
174 from mercurial import ( |
167 from mercurial import ( |
175 cmdutil, |
|
176 color, |
168 color, |
177 commands, |
169 commands |
178 ) |
170 ) |
179 |
171 |
180 cmdtable = {} |
|
181 command = cmdutil.command(cmdtable) |
|
182 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
172 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
183 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
173 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
184 # be specifying the version(s) of Mercurial they are tested with, or |
174 # be specifying the version(s) of Mercurial they are tested with, or |
185 # leave the attribute unspecified. |
175 # leave the attribute unspecified. |
186 testedwith = 'ships-with-hg-core' |
176 testedwith = 'ships-with-hg-core' |
192 if entry[1] == 'color': |
182 if entry[1] == 'color': |
193 patch = (entry[3].replace(' (EXPERIMENTAL)', ''),) |
183 patch = (entry[3].replace(' (EXPERIMENTAL)', ''),) |
194 new = entry[:3] + patch + entry[4:] |
184 new = entry[:3] + patch + entry[4:] |
195 commands.globalopts[idx] = new |
185 commands.globalopts[idx] = new |
196 break |
186 break |
197 |
|
198 @command('debugcolor', |
|
199 [('', 'style', None, _('show all configured styles'))], |
|
200 'hg debugcolor') |
|
201 def debugcolor(ui, repo, **opts): |
|
202 """show available color, effects or style""" |
|
203 ui.write(('color mode: %s\n') % ui._colormode) |
|
204 if opts.get('style'): |
|
205 return _debugdisplaystyle(ui) |
|
206 else: |
|
207 return _debugdisplaycolor(ui) |
|
208 |
|
209 def _debugdisplaycolor(ui): |
|
210 oldstyle = ui._styles.copy() |
|
211 try: |
|
212 ui._styles.clear() |
|
213 for effect in color._effects.keys(): |
|
214 ui._styles[effect] = effect |
|
215 if ui._terminfoparams: |
|
216 for k, v in ui.configitems('color'): |
|
217 if k.startswith('color.'): |
|
218 ui._styles[k] = k[6:] |
|
219 elif k.startswith('terminfo.'): |
|
220 ui._styles[k] = k[9:] |
|
221 ui.write(_('available colors:\n')) |
|
222 # sort label with a '_' after the other to group '_background' entry. |
|
223 items = sorted(ui._styles.items(), |
|
224 key=lambda i: ('_' in i[0], i[0], i[1])) |
|
225 for colorname, label in items: |
|
226 ui.write(('%s\n') % colorname, label=label) |
|
227 finally: |
|
228 ui._styles.clear() |
|
229 ui._styles.update(oldstyle) |
|
230 |
|
231 def _debugdisplaystyle(ui): |
|
232 ui.write(_('available style:\n')) |
|
233 width = max(len(s) for s in ui._styles) |
|
234 for label, effects in sorted(ui._styles.items()): |
|
235 ui.write('%s' % label, label=label) |
|
236 if effects: |
|
237 # 50 |
|
238 ui.write(': ') |
|
239 ui.write(' ' * (max(0, width - len(label)))) |
|
240 ui.write(', '.join(ui.label(e, e) for e in effects.split())) |
|
241 ui.write('\n') |
|