Mercurial > hg
annotate hgext/color.py @ 10398:ace3cf2bc991
tests: don't just silently strip port numbers
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 08 Feb 2010 02:53:41 +0100 |
parents | 08a0f04b56bd |
children | 5ddde896a19d 2253715fde97 |
rev | line source |
---|---|
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
1 # color.py color output for the status and qseries commands |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
2 # |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
3 # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
4 # |
5792
956e01c31914
color extension: change from GPL3 to 2
Kevin Christen <kevin.christen@gmail.com>
parents:
5787
diff
changeset
|
5 # This program is free software; you can redistribute it and/or modify it |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
6 # under the terms of the GNU General Public License as published by the |
5792
956e01c31914
color extension: change from GPL3 to 2
Kevin Christen <kevin.christen@gmail.com>
parents:
5787
diff
changeset
|
7 # Free Software Foundation; either version 2 of the License, or (at your |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
8 # option) any later version. |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
9 # |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, but |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
11 # WITHOUT ANY WARRANTY; without even the implied warranty of |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
13 # Public License for more details. |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
14 # |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
15 # You should have received a copy of the GNU General Public License along |
5792
956e01c31914
color extension: change from GPL3 to 2
Kevin Christen <kevin.christen@gmail.com>
parents:
5787
diff
changeset
|
16 # with this program; if not, write to the Free Software Foundation, Inc., |
956e01c31914
color extension: change from GPL3 to 2
Kevin Christen <kevin.christen@gmail.com>
parents:
5787
diff
changeset
|
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
18 |
8894
868670dbc237
extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents:
8866
diff
changeset
|
19 '''colorize output from some commands |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
20 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
21 This extension modifies the status and resolve commands to add color to their |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
22 output to reflect file status, the qseries command to add color to reflect |
7988
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
23 patch status (applied, unapplied, missing), and to diff-related |
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
24 commands to highlight additions, removals, diff headers, and trailing |
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
25 whitespace. |
7457
a70fb83cbb9e
diff colorization: finish highlighting trailing whitespace
Georg Brandl <georg@python.org>
parents:
7456
diff
changeset
|
26 |
7988
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
27 Other effects in addition to color, like bold and underlined text, are |
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
28 also available. Effects are rendered with the ECMA-48 SGR control |
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
29 function (aka ANSI escape codes). This module also provides the |
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
30 render_text function, which can be used to add effects to any text. |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
31 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
32 Default effects may be overridden from the .hgrc file:: |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
33 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
34 [color] |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
35 status.modified = blue bold underline red_background |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
36 status.added = green bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
37 status.removed = red bold blue_background |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
38 status.deleted = cyan bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
39 status.unknown = magenta bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
40 status.ignored = black bold |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
41 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
42 # 'none' turns off all effects |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
43 status.clean = none |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
44 status.copied = none |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
45 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
46 qseries.applied = blue bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
47 qseries.unapplied = black bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
48 qseries.missing = red bold |
7456 | 49 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
50 diff.diffline = bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
51 diff.extended = cyan bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
52 diff.file_a = red bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
53 diff.file_b = green bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
54 diff.hunk = magenta |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
55 diff.deleted = red |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
56 diff.inserted = green |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
57 diff.changed = white |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
58 diff.trailingwhitespace = bold red_background |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
59 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
60 resolve.unresolved = red bold |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
61 resolve.resolved = green bold |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
62 |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
63 bookmarks.current = green |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
64 ''' |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
65 |
8623
0c159aa7b329
color: replace re.split with ui.configlist
Martin Geisler <mg@lazybytes.net>
parents:
8622
diff
changeset
|
66 import os, sys |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
67 |
8963
a4ceae3aa7be
color: wrap qdiff/qseries after all extensions are loaded
Brodie Rao <me+hg@dackz.net>
parents:
8945
diff
changeset
|
68 from mercurial import cmdutil, commands, extensions, error |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
69 from mercurial.i18n import _ |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
70 |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
71 # start and stop parameters for effects |
7459
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
72 _effect_params = {'none': 0, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
73 'black': 30, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
74 'red': 31, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
75 'green': 32, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
76 'yellow': 33, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
77 'blue': 34, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
78 'magenta': 35, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
79 'cyan': 36, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
80 'white': 37, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
81 'bold': 1, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
82 'italic': 3, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
83 'underline': 4, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
84 'inverse': 7, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
85 'black_background': 40, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
86 'red_background': 41, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
87 'green_background': 42, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
88 'yellow_background': 43, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
89 'blue_background': 44, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
90 'purple_background': 45, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
91 'cyan_background': 46, |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
92 'white_background': 47} |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
93 |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
94 def render_effects(text, effects): |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
95 'Wrap text in commands to turn on each effect.' |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
96 start = [str(_effect_params[e]) for e in ['none'] + effects] |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
97 start = '\033[' + ';'.join(start) + 'm' |
7459
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
98 stop = '\033[' + str(_effect_params['none']) + 'm' |
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
99 return ''.join([start, text, stop]) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
100 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
101 def _colorstatuslike(abbreviations, effectdefs, orig, ui, repo, *pats, **opts): |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
102 '''run a status-like command with colorized output''' |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
103 delimiter = opts.get('print0') and '\0' or '\n' |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
104 |
7419
efe31fbe6cf0
color: don't run status twice for -n
Brendan Cully <brendan@kublai.com>
parents:
7418
diff
changeset
|
105 nostatus = opts.get('no_status') |
efe31fbe6cf0
color: don't run status twice for -n
Brendan Cully <brendan@kublai.com>
parents:
7418
diff
changeset
|
106 opts['no_status'] = False |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
107 # run original command and capture its output |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
108 ui.pushbuffer() |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
109 retval = orig(ui, repo, *pats, **opts) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
110 # filter out empty strings |
10222
98f630e15d82
color: improve coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10046
diff
changeset
|
111 lines_with_status = [line for line in ui.popbuffer().split(delimiter) if line] |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
112 |
7419
efe31fbe6cf0
color: don't run status twice for -n
Brendan Cully <brendan@kublai.com>
parents:
7418
diff
changeset
|
113 if nostatus: |
efe31fbe6cf0
color: don't run status twice for -n
Brendan Cully <brendan@kublai.com>
parents:
7418
diff
changeset
|
114 lines = [l[2:] for l in lines_with_status] |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
115 else: |
7419
efe31fbe6cf0
color: don't run status twice for -n
Brendan Cully <brendan@kublai.com>
parents:
7418
diff
changeset
|
116 lines = lines_with_status |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
117 |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
118 # apply color to output and display it |
8624
2b3dec0ef3ae
replace xrange(0, n) with xrange(n)
Martin Geisler <mg@lazybytes.net>
parents:
8623
diff
changeset
|
119 for i in xrange(len(lines)): |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
120 status = abbreviations[lines_with_status[i][0]] |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
121 effects = effectdefs[status] |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
122 if effects: |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
123 lines[i] = render_effects(lines[i], effects) |
7455 | 124 ui.write(lines[i] + delimiter) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
125 return retval |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
126 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
127 |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
128 _status_abbreviations = { 'M': 'modified', |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
129 'A': 'added', |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
130 'R': 'removed', |
5796
7705d308eb5e
Fix status char in color extension for deleted (missing) files.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5792
diff
changeset
|
131 '!': 'deleted', |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
132 '?': 'unknown', |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
133 'I': 'ignored', |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
134 'C': 'clean', |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
135 ' ': 'copied', } |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
136 |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
137 _status_effects = { 'modified': ['blue', 'bold'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
138 'added': ['green', 'bold'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
139 'removed': ['red', 'bold'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
140 'deleted': ['cyan', 'bold', 'underline'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
141 'unknown': ['magenta', 'bold', 'underline'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
142 'ignored': ['black', 'bold'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
143 'clean': ['none'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
144 'copied': ['none'], } |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
145 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
146 def colorstatus(orig, ui, repo, *pats, **opts): |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
147 '''run the status command with colored output''' |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
148 return _colorstatuslike(_status_abbreviations, _status_effects, |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
149 orig, ui, repo, *pats, **opts) |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
150 |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
151 |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
152 _resolve_abbreviations = { 'U': 'unresolved', |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
153 'R': 'resolved', } |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
154 |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
155 _resolve_effects = { 'unresolved': ['red', 'bold'], |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
156 'resolved': ['green', 'bold'], } |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
157 |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
158 def colorresolve(orig, ui, repo, *pats, **opts): |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
159 '''run the resolve command with colored output''' |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
160 if not opts.get('list'): |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
161 # only colorize for resolve -l |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
162 return orig(ui, repo, *pats, **opts) |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
163 return _colorstatuslike(_resolve_abbreviations, _resolve_effects, |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
164 orig, ui, repo, *pats, **opts) |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
165 |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
166 |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
167 _bookmark_effects = { 'current': ['green'] } |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
168 |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
169 def colorbookmarks(orig, ui, repo, *pats, **opts): |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
170 def colorize(orig, s): |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
171 lines = s.split('\n') |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
172 for i, line in enumerate(lines): |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
173 if line.startswith(" *"): |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
174 lines[i] = render_effects(line, _bookmark_effects['current']) |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
175 orig('\n'.join(lines)) |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
176 oldwrite = extensions.wrapfunction(ui, 'write', colorize) |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
177 try: |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
178 orig(ui, repo, *pats, **opts) |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
179 finally: |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
180 ui.write = oldwrite |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
181 |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
182 def colorqseries(orig, ui, repo, *dummy, **opts): |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
183 '''run the qseries command with colored output''' |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
184 ui.pushbuffer() |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
185 retval = orig(ui, repo, **opts) |
9311
e37e9904bf10
color: simplify & improve colorization of qseries
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9255
diff
changeset
|
186 patchlines = ui.popbuffer().splitlines() |
e37e9904bf10
color: simplify & improve colorization of qseries
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
9255
diff
changeset
|
187 patchnames = repo.mq.series |
6855
09db2b8236ec
Apply color to output of qseries --verbose
Kevin Christen <kevin.christen@gmail.com>
parents:
6854
diff
changeset
|
188 |
9374
ad73f6986ef5
color: no need for itertools, zip() is good enough
Patrick Mezard <pmezard@gmail.com>
parents:
9311
diff
changeset
|
189 for patch, patchname in zip(patchlines, patchnames): |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
190 if opts['missing']: |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
191 effects = _patch_effects['missing'] |
6855
09db2b8236ec
Apply color to output of qseries --verbose
Kevin Christen <kevin.christen@gmail.com>
parents:
6854
diff
changeset
|
192 # Determine if patch is applied. |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10223
diff
changeset
|
193 elif [applied for applied in repo.mq.applied |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10223
diff
changeset
|
194 if patchname == applied.name]: |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
195 effects = _patch_effects['applied'] |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
196 else: |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
197 effects = _patch_effects['unapplied'] |
9017
c24c9ce0cdcf
color: don't highlight the summary part of the qseries command
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
8963
diff
changeset
|
198 |
c24c9ce0cdcf
color: don't highlight the summary part of the qseries command
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
8963
diff
changeset
|
199 patch = patch.replace(patchname, render_effects(patchname, effects), 1) |
c24c9ce0cdcf
color: don't highlight the summary part of the qseries command
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
8963
diff
changeset
|
200 ui.write(patch + '\n') |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
201 return retval |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
202 |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
203 _patch_effects = { 'applied': ['blue', 'bold', 'underline'], |
9520
bcc27ee3a37b
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
8963
diff
changeset
|
204 'missing': ['red', 'bold'], |
bcc27ee3a37b
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
8963
diff
changeset
|
205 'unapplied': ['black', 'bold'], } |
9551
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
206 def colorwrap(orig, *args): |
7456 | 207 '''wrap ui.write for colored diff output''' |
9551
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
208 def _colorize(s): |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
209 lines = s.split('\n') |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
210 for i, line in enumerate(lines): |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
211 stripline = line |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
212 if line and line[0] in '+-': |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
213 # highlight trailing whitespace, but only in changed lines |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
214 stripline = line.rstrip() |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
215 for prefix, style in _diff_prefixes: |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
216 if stripline.startswith(prefix): |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
217 lines[i] = render_effects(stripline, _diff_effects[style]) |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
218 break |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
219 if line != stripline: |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
220 lines[i] += render_effects( |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
221 line[len(stripline):], _diff_effects['trailingwhitespace']) |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
222 return '\n'.join(lines) |
3e698434b990
color: allow multiple args to ui.write()
Kevin Bullock <kbullock@ringworld.org>
parents:
9550
diff
changeset
|
223 orig(*[_colorize(s) for s in args]) |
7456 | 224 |
225 def colorshowpatch(orig, self, node): | |
226 '''wrap cmdutil.changeset_printer.showpatch with colored output''' | |
227 oldwrite = extensions.wrapfunction(self.ui, 'write', colorwrap) | |
228 try: | |
229 orig(self, node) | |
230 finally: | |
231 self.ui.write = oldwrite | |
232 | |
9641 | 233 def colordiffstat(orig, s): |
234 lines = s.split('\n') | |
235 for i, line in enumerate(lines): | |
236 if line and line[-1] in '+-': | |
237 name, graph = line.rsplit(' ', 1) | |
238 graph = graph.replace('-', | |
239 render_effects('-', _diff_effects['deleted'])) | |
240 graph = graph.replace('+', | |
241 render_effects('+', _diff_effects['inserted'])) | |
242 lines[i] = ' '.join([name, graph]) | |
243 orig('\n'.join(lines)) | |
244 | |
7456 | 245 def colordiff(orig, ui, repo, *pats, **opts): |
246 '''run the diff command with colored output''' | |
9641 | 247 if opts.get('stat'): |
248 wrapper = colordiffstat | |
249 else: | |
250 wrapper = colorwrap | |
251 oldwrite = extensions.wrapfunction(ui, 'write', wrapper) | |
7456 | 252 try: |
253 orig(ui, repo, *pats, **opts) | |
254 finally: | |
255 ui.write = oldwrite | |
256 | |
10004
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
257 def colorchurn(orig, ui, repo, *pats, **opts): |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
258 '''run the churn command with colored output''' |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
259 if not opts.get('diffstat'): |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
260 return orig(ui, repo, *pats, **opts) |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
261 oldwrite = extensions.wrapfunction(ui, 'write', colordiffstat) |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
262 try: |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
263 orig(ui, repo, *pats, **opts) |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
264 finally: |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
265 ui.write = oldwrite |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
266 |
7456 | 267 _diff_prefixes = [('diff', 'diffline'), |
268 ('copy', 'extended'), | |
269 ('rename', 'extended'), | |
7539
92c373f8135f
color: fix colorization of the 'old mode' git diff metadata
Gilles Moris <gilles.moris@free.fr>
parents:
7459
diff
changeset
|
270 ('old', 'extended'), |
7456 | 271 ('new', 'extended'), |
272 ('deleted', 'extended'), | |
273 ('---', 'file_a'), | |
274 ('+++', 'file_b'), | |
275 ('@', 'hunk'), | |
276 ('-', 'deleted'), | |
277 ('+', 'inserted')] | |
278 | |
8630
8ff65f7e3273
color: cleanup extra commas
Martin Geisler <mg@lazybytes.net>
parents:
8624
diff
changeset
|
279 _diff_effects = {'diffline': ['bold'], |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
280 'extended': ['cyan', 'bold'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
281 'file_a': ['red', 'bold'], |
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
282 'file_b': ['green', 'bold'], |
8630
8ff65f7e3273
color: cleanup extra commas
Martin Geisler <mg@lazybytes.net>
parents:
8624
diff
changeset
|
283 'hunk': ['magenta'], |
8ff65f7e3273
color: cleanup extra commas
Martin Geisler <mg@lazybytes.net>
parents:
8624
diff
changeset
|
284 'deleted': ['red'], |
8ff65f7e3273
color: cleanup extra commas
Martin Geisler <mg@lazybytes.net>
parents:
8624
diff
changeset
|
285 'inserted': ['green'], |
8ff65f7e3273
color: cleanup extra commas
Martin Geisler <mg@lazybytes.net>
parents:
8624
diff
changeset
|
286 'changed': ['white'], |
8ff65f7e3273
color: cleanup extra commas
Martin Geisler <mg@lazybytes.net>
parents:
8624
diff
changeset
|
287 'trailingwhitespace': ['bold', 'red_background']} |
7456 | 288 |
9711 | 289 def extsetup(ui): |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
290 '''Initialize the extension.''' |
7456 | 291 _setupcmd(ui, 'diff', commands.table, colordiff, _diff_effects) |
292 _setupcmd(ui, 'incoming', commands.table, None, _diff_effects) | |
293 _setupcmd(ui, 'log', commands.table, None, _diff_effects) | |
294 _setupcmd(ui, 'outgoing', commands.table, None, _diff_effects) | |
295 _setupcmd(ui, 'tip', commands.table, None, _diff_effects) | |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
296 _setupcmd(ui, 'status', commands.table, colorstatus, _status_effects) |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
297 _setupcmd(ui, 'resolve', commands.table, colorresolve, _resolve_effects) |
8963
a4ceae3aa7be
color: wrap qdiff/qseries after all extensions are loaded
Brodie Rao <me+hg@dackz.net>
parents:
8945
diff
changeset
|
298 |
8278
1f9787de17d9
color: look for mq with extensions.find
Martin Geisler <mg@lazybytes.net>
parents:
7988
diff
changeset
|
299 try: |
1f9787de17d9
color: look for mq with extensions.find
Martin Geisler <mg@lazybytes.net>
parents:
7988
diff
changeset
|
300 mq = extensions.find('mq') |
9412
3a78bbc57660
color: do all setup in uisetup
Martin Geisler <mg@lazybytes.net>
parents:
9374
diff
changeset
|
301 _setupcmd(ui, 'qdiff', mq.cmdtable, colordiff, _diff_effects) |
3a78bbc57660
color: do all setup in uisetup
Martin Geisler <mg@lazybytes.net>
parents:
9374
diff
changeset
|
302 _setupcmd(ui, 'qseries', mq.cmdtable, colorqseries, _patch_effects) |
8278
1f9787de17d9
color: look for mq with extensions.find
Martin Geisler <mg@lazybytes.net>
parents:
7988
diff
changeset
|
303 except KeyError: |
9711 | 304 mq = None |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
305 |
9550
3bcb28131bab
color: add support for record extension
TK Soh <teekaysoh@gmail.com>
parents:
9523
diff
changeset
|
306 try: |
3bcb28131bab
color: add support for record extension
TK Soh <teekaysoh@gmail.com>
parents:
9523
diff
changeset
|
307 rec = extensions.find('record') |
3bcb28131bab
color: add support for record extension
TK Soh <teekaysoh@gmail.com>
parents:
9523
diff
changeset
|
308 _setupcmd(ui, 'record', rec.cmdtable, colordiff, _diff_effects) |
3bcb28131bab
color: add support for record extension
TK Soh <teekaysoh@gmail.com>
parents:
9523
diff
changeset
|
309 except KeyError: |
9711 | 310 rec = None |
311 | |
312 if mq and rec: | |
313 _setupcmd(ui, 'qrecord', rec.cmdtable, colordiff, _diff_effects) | |
10004
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
314 try: |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
315 churn = extensions.find('churn') |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
316 _setupcmd(ui, 'churn', churn.cmdtable, colorchurn, _diff_effects) |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
317 except KeyError: |
af04a3dea4cd
color: add support for churn --diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9711
diff
changeset
|
318 churn = None |
9550
3bcb28131bab
color: add support for record extension
TK Soh <teekaysoh@gmail.com>
parents:
9523
diff
changeset
|
319 |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
320 try: |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
321 bookmarks = extensions.find('bookmarks') |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
322 _setupcmd(ui, 'bookmarks', bookmarks.cmdtable, colorbookmarks, |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
323 _bookmark_effects) |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
324 except KeyError: |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
325 # The bookmarks extension is not enabled |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
326 pass |
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
327 |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
328 def _setupcmd(ui, cmd, table, func, effectsmap): |
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
329 '''patch in command to command table and load effect map''' |
7455 | 330 def nocolor(orig, *args, **opts): |
331 | |
332 if (opts['no_color'] or opts['color'] == 'never' or | |
333 (opts['color'] == 'auto' and (os.environ.get('TERM') == 'dumb' | |
334 or not sys.__stdout__.isatty()))): | |
10045
d1f9640e9a67
color: Do not pass --color, --no-color parameters to wrapped function
David Soria Parra <dsp@php.net>
parents:
10004
diff
changeset
|
335 del opts['no_color'] |
d1f9640e9a67
color: Do not pass --color, --no-color parameters to wrapped function
David Soria Parra <dsp@php.net>
parents:
10004
diff
changeset
|
336 del opts['color'] |
7455 | 337 return orig(*args, **opts) |
338 | |
7456 | 339 oldshowpatch = extensions.wrapfunction(cmdutil.changeset_printer, |
340 'showpatch', colorshowpatch) | |
10045
d1f9640e9a67
color: Do not pass --color, --no-color parameters to wrapped function
David Soria Parra <dsp@php.net>
parents:
10004
diff
changeset
|
341 del opts['no_color'] |
d1f9640e9a67
color: Do not pass --color, --no-color parameters to wrapped function
David Soria Parra <dsp@php.net>
parents:
10004
diff
changeset
|
342 del opts['color'] |
7456 | 343 try: |
344 if func is not None: | |
345 return func(orig, *args, **opts) | |
346 return orig(*args, **opts) | |
347 finally: | |
348 cmdutil.changeset_printer.showpatch = oldshowpatch | |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
349 |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
7213
diff
changeset
|
350 entry = extensions.wrapcommand(table, cmd, nocolor) |
7455 | 351 entry[1].extend([ |
352 ('', 'color', 'auto', _("when to colorize (always, auto, or never)")), | |
9478
32ec70799172
color: mark --no-color as deprecated (--color=never has the same effect)
Brodie Rao <me+hg@dackz.net>
parents:
9412
diff
changeset
|
353 ('', 'no-color', None, _("don't colorize output (DEPRECATED)")), |
7455 | 354 ]) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
355 |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
356 for status in effectsmap: |
8945
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
357 configkey = cmd + '.' + status |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
358 effects = ui.configlist('color', configkey) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
359 if effects: |
8945
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
360 good = [] |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
361 for e in effects: |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
362 if e in _effect_params: |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
363 good.append(e) |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
364 else: |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
365 ui.warn(_("ignoring unknown color/effect %r " |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
366 "(configured in color.%s)\n") |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
367 % (e, configkey)) |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
368 effectsmap[status] = good |