Mercurial > hg
annotate hgext/color.py @ 19234:7bbad79b9542
merge with stable
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 23 May 2013 17:52:21 -0500 |
parents | f184fe1e2ac5 |
children | 8ddc3cd962ba |
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 # |
15771
425c1309718f
color: Use the same GPL boilerplate as most hg files
Augie Fackler <durin42@gmail.com>
parents:
15048
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
425c1309718f
color: Use the same GPL boilerplate as most hg files
Augie Fackler <durin42@gmail.com>
parents:
15048
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
7 |
8894
868670dbc237
extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents:
8866
diff
changeset
|
8 '''colorize output from some commands |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
9 |
13638
72040d98ff0a
color: wrap lines in docstring
Martin Geisler <mg@aragost.com>
parents:
13635
diff
changeset
|
10 This extension modifies the status and resolve commands to add color |
72040d98ff0a
color: wrap lines in docstring
Martin Geisler <mg@aragost.com>
parents:
13635
diff
changeset
|
11 to their output to reflect file status, the qseries command to add |
72040d98ff0a
color: wrap lines in docstring
Martin Geisler <mg@aragost.com>
parents:
13635
diff
changeset
|
12 color to reflect patch status (applied, unapplied, missing), and to |
72040d98ff0a
color: wrap lines in docstring
Martin Geisler <mg@aragost.com>
parents:
13635
diff
changeset
|
13 diff-related commands to highlight additions, removals, diff headers, |
72040d98ff0a
color: wrap lines in docstring
Martin Geisler <mg@aragost.com>
parents:
13635
diff
changeset
|
14 and trailing whitespace. |
7457
a70fb83cbb9e
diff colorization: finish highlighting trailing whitespace
Georg Brandl <georg@python.org>
parents:
7456
diff
changeset
|
15 |
7988
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
16 Other effects in addition to color, like bold and underlined text, are |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
17 also available. By default, the terminfo database is used to find the |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
18 terminal codes used to change color and effect. If terminfo is not |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
19 available, then effects are rendered with the ECMA-48 SGR control |
13635
c9ddc39c21b6
color: don't mention internal function in docstring
Martin Geisler <mg@aragost.com>
parents:
13361
diff
changeset
|
20 function (aka ANSI escape codes). |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
21 |
12083
ebfc46929f3e
help: refer to user configuration file more consistently
Brodie Rao <brodie@bitheap.org>
parents:
11732
diff
changeset
|
22 Default effects may be overridden from your configuration file:: |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
23 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
24 [color] |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
25 status.modified = blue bold underline red_background |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
26 status.added = green bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
27 status.removed = red bold blue_background |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
28 status.deleted = cyan bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
29 status.unknown = magenta bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
30 status.ignored = black bold |
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 # 'none' turns off all effects |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
33 status.clean = none |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
34 status.copied = none |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
35 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
36 qseries.applied = blue bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
37 qseries.unapplied = black bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
38 qseries.missing = red bold |
7456 | 39 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
40 diff.diffline = bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
41 diff.extended = cyan bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
42 diff.file_a = red bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
43 diff.file_b = green bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
44 diff.hunk = magenta |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
45 diff.deleted = red |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
46 diff.inserted = green |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
47 diff.changed = white |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
48 diff.trailingwhitespace = bold red_background |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
49 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
50 resolve.unresolved = red bold |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
51 resolve.resolved = green bold |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
52 |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
53 bookmarks.current = green |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
54 |
11969
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
55 branches.active = none |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
56 branches.closed = black bold |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
57 branches.current = green |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
58 branches.inactive = none |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
59 |
15048
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
60 tags.normal = green |
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
61 tags.local = black bold |
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
62 |
19214
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
63 rebase.rebased = blue |
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
64 rebase.remaining = red bold |
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
65 |
19215
f184fe1e2ac5
summary: add a histedit hook
Bryan O'Sullivan <bryano@fb.com>
parents:
19214
diff
changeset
|
66 histedit.remaining = red bold |
f184fe1e2ac5
summary: add a histedit hook
Bryan O'Sullivan <bryano@fb.com>
parents:
19214
diff
changeset
|
67 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
68 The available effects in terminfo mode are 'blink', 'bold', 'dim', |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
69 'inverse', 'invisible', 'italic', 'standout', and 'underline'; in |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
70 ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
71 'underline'. How each is rendered depends on the terminal emulator. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
72 Some may not be available for a given terminal type, and will be |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
73 silently ignored. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
74 |
14769
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
75 Note that on some systems, terminfo mode may cause problems when using |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
76 color with the pager extension and less -R. less with the -R option |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
77 will only display ECMA-48 color codes, and terminfo mode may sometimes |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
78 emit codes that less doesn't understand. You can work around this by |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
79 either using ansi mode (or auto mode), or by using less -r (which will |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
80 pass through all terminal control codes, not just color control |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
81 codes). |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
82 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
83 Because there are only eight standard colors, this module allows you |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
84 to define color names for other color slots which might be available |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
85 for your terminal type, assuming terminfo mode. For instance:: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
86 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
87 color.brightblue = 12 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
88 color.pink = 207 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
89 color.orange = 202 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
90 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
91 to set 'brightblue' to color slot 12 (useful for 16 color terminals |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
92 that have brighter colors defined in the upper eight) and, 'pink' and |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
93 'orange' to colors in 256-color xterm's default color cube. These |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
94 defined colors may then be used as any of the pre-defined eight, |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
95 including appending '_background' to set the background to that color. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
96 |
14769
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
97 By default, the color extension will use ANSI mode (or win32 mode on |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
98 Windows) if it detects a terminal. To override auto mode (to enable |
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
99 terminfo mode, for example), set the following configuration option:: |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
100 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
101 [color] |
14769
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
102 mode = terminfo |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
103 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
104 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
105 disable color. |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
106 ''' |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
107 |
14139 | 108 import os |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
109 |
12089
70f4a0f4e9a3
color: accept usual boolean values as synonyms for always and never
Augie Fackler <durin42@gmail.com>
parents:
12084
diff
changeset
|
110 from mercurial import commands, dispatch, extensions, ui as uimod, util |
18921
ac31f586eff7
color: add missing import of error
Bryan O'Sullivan <bryano@fb.com>
parents:
18829
diff
changeset
|
111 from mercurial import templater, error |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
112 from mercurial.i18n import _ |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
113 |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
15771
diff
changeset
|
114 testedwith = 'internal' |
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
15771
diff
changeset
|
115 |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
116 # start and stop parameters for effects |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
117 _effects = {'none': 0, 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
118 'blue': 34, 'magenta': 35, 'cyan': 36, 'white': 37, 'bold': 1, |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
119 'italic': 3, 'underline': 4, 'inverse': 7, |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
120 'black_background': 40, 'red_background': 41, |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
121 'green_background': 42, 'yellow_background': 43, |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
122 'blue_background': 44, 'purple_background': 45, |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
123 'cyan_background': 46, 'white_background': 47} |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
124 |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
125 def _terminfosetup(ui, mode): |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
126 '''Initialize terminfo data and the terminal if we're in terminfo mode.''' |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
127 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
128 global _terminfo_params |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
129 # If we failed to load curses, we go ahead and return. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
130 if not _terminfo_params: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
131 return |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
132 # Otherwise, see what the config file says. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
133 if mode not in ('auto', 'terminfo'): |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
134 return |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
135 |
13998
14c7526fed89
color: code simplification
Patrick Mezard <pmezard@gmail.com>
parents:
13987
diff
changeset
|
136 _terminfo_params.update((key[6:], (False, int(val))) |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
137 for key, val in ui.configitems('color') |
13998
14c7526fed89
color: code simplification
Patrick Mezard <pmezard@gmail.com>
parents:
13987
diff
changeset
|
138 if key.startswith('color.')) |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
139 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
140 try: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
141 curses.setupterm() |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
142 except curses.error, e: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
143 _terminfo_params = {} |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
144 return |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
145 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
146 for key, (b, e) in _terminfo_params.items(): |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
147 if not b: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
148 continue |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
149 if not curses.tigetstr(e): |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
150 # Most terminals don't support dim, invis, etc, so don't be |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
151 # noisy and use ui.debug(). |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
152 ui.debug("no terminfo entry for %s\n" % e) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
153 del _terminfo_params[key] |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
154 if not curses.tigetstr('setaf') or not curses.tigetstr('setab'): |
14758
1e6661e09818
color: be silent when falling back to ECMA-48 mode if "auto" mode was desired
Danek Duvall <duvall@comfychair.org>
parents:
14516
diff
changeset
|
155 # Only warn about missing terminfo entries if we explicitly asked for |
1e6661e09818
color: be silent when falling back to ECMA-48 mode if "auto" mode was desired
Danek Duvall <duvall@comfychair.org>
parents:
14516
diff
changeset
|
156 # terminfo mode. |
1e6661e09818
color: be silent when falling back to ECMA-48 mode if "auto" mode was desired
Danek Duvall <duvall@comfychair.org>
parents:
14516
diff
changeset
|
157 if mode == "terminfo": |
1e6661e09818
color: be silent when falling back to ECMA-48 mode if "auto" mode was desired
Danek Duvall <duvall@comfychair.org>
parents:
14516
diff
changeset
|
158 ui.warn(_("no terminfo entry for setab/setaf: reverting to " |
1e6661e09818
color: be silent when falling back to ECMA-48 mode if "auto" mode was desired
Danek Duvall <duvall@comfychair.org>
parents:
14516
diff
changeset
|
159 "ECMA-48 color\n")) |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
160 _terminfo_params = {} |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
161 |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
162 def _modesetup(ui, opts): |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
163 global _terminfo_params |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
164 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
165 coloropt = opts['color'] |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
166 auto = coloropt == 'auto' |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
167 always = not auto and util.parsebool(coloropt) |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
168 if not always and not auto: |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
169 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
170 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
171 formatted = always or (os.environ.get('TERM') != 'dumb' and ui.formatted()) |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
172 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
173 mode = ui.config('color', 'mode', 'auto') |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
174 realmode = mode |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
175 if mode == 'auto': |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
176 if os.name == 'nt' and 'TERM' not in os.environ: |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
177 # looks line a cmd.exe console, use win32 API or nothing |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
178 realmode = 'win32' |
14769
9adce4b38ed1
color: for the sake of "less -R", default to ansi in auto mode (issue2792)
Brodie Rao <brodie@bitheap.org>
parents:
14768
diff
changeset
|
179 else: |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
180 realmode = 'ansi' |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
181 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
182 if realmode == 'win32': |
14989
9e9d4a762586
color.py - clear _terminfo_params in win32 mode
Andrei Vermel <avermel@mail.ru>
parents:
14769
diff
changeset
|
183 _terminfo_params = {} |
14768
55db12e54450
color: fix TypeError with auto mode on win32 when colors aren't available (issue2871)
Brodie Rao <brodie@bitheap.org>
parents:
14758
diff
changeset
|
184 if not w32effects: |
55db12e54450
color: fix TypeError with auto mode on win32 when colors aren't available (issue2871)
Brodie Rao <brodie@bitheap.org>
parents:
14758
diff
changeset
|
185 if mode == 'win32': |
55db12e54450
color: fix TypeError with auto mode on win32 when colors aren't available (issue2871)
Brodie Rao <brodie@bitheap.org>
parents:
14758
diff
changeset
|
186 # only warn if color.mode is explicitly set to win32 |
55db12e54450
color: fix TypeError with auto mode on win32 when colors aren't available (issue2871)
Brodie Rao <brodie@bitheap.org>
parents:
14758
diff
changeset
|
187 ui.warn(_('warning: failed to set color mode to %s\n') % mode) |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
188 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
189 _effects.update(w32effects) |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
190 elif realmode == 'ansi': |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
191 _terminfo_params = {} |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
192 elif realmode == 'terminfo': |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
193 _terminfosetup(ui, mode) |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
194 if not _terminfo_params: |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
195 if mode == 'terminfo': |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
196 ## FIXME Shouldn't we return None in this case too? |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
197 # only warn if color.mode is explicitly set to win32 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
198 ui.warn(_('warning: failed to set color mode to %s\n') % mode) |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
199 realmode = 'ansi' |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
200 else: |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
201 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
202 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
203 if always or (auto and formatted): |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
204 return realmode |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
205 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
206 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
207 try: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
208 import curses |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
209 # Mapping from effect name to terminfo attribute name or color number. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
210 # This will also force-load the curses module. |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
211 _terminfo_params = {'none': (True, 'sgr0'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
212 'standout': (True, 'smso'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
213 'underline': (True, 'smul'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
214 'reverse': (True, 'rev'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
215 'inverse': (True, 'rev'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
216 'blink': (True, 'blink'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
217 'dim': (True, 'dim'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
218 'bold': (True, 'bold'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
219 'invisible': (True, 'invis'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
220 'italic': (True, 'sitm'), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
221 'black': (False, curses.COLOR_BLACK), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
222 'red': (False, curses.COLOR_RED), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
223 'green': (False, curses.COLOR_GREEN), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
224 'yellow': (False, curses.COLOR_YELLOW), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
225 'blue': (False, curses.COLOR_BLUE), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
226 'magenta': (False, curses.COLOR_MAGENTA), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
227 'cyan': (False, curses.COLOR_CYAN), |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
228 'white': (False, curses.COLOR_WHITE)} |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
229 except ImportError: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
230 _terminfo_params = False |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
231 |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
232 _styles = {'grep.match': 'red bold', |
17806
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
233 'grep.linenumber': 'green', |
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
234 'grep.rev': 'green', |
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
235 'grep.change': 'green', |
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
236 'grep.sep': 'cyan', |
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
237 'grep.filename': 'magenta', |
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
238 'grep.user': 'magenta', |
dc7010ed0101
grep: colorize all fields
Idan Kamara <idankk86@gmail.com>
parents:
17424
diff
changeset
|
239 'grep.date': 'magenta', |
13361
5b4252364ff9
bookmarks: move color style to color
Matt Mackall <mpm@selenic.com>
parents:
12807
diff
changeset
|
240 'bookmarks.current': 'green', |
11969
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
241 'branches.active': 'none', |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
242 'branches.closed': 'black bold', |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
243 'branches.current': 'green', |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
244 'branches.inactive': 'none', |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
245 'diff.changed': 'white', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
246 'diff.deleted': 'red', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
247 'diff.diffline': 'bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
248 'diff.extended': 'cyan bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
249 'diff.file_a': 'red bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
250 'diff.file_b': 'green bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
251 'diff.hunk': 'magenta', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
252 'diff.inserted': 'green', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
253 'diff.trailingwhitespace': 'bold red_background', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
254 'diffstat.deleted': 'red', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
255 'diffstat.inserted': 'green', |
19215
f184fe1e2ac5
summary: add a histedit hook
Bryan O'Sullivan <bryano@fb.com>
parents:
19214
diff
changeset
|
256 'histedit.remaining': 'red bold', |
13774
1ce0e80799c0
ui: label prompts, default to yellow prompts
Martin Geisler <mg@lazybytes.net>
parents:
13648
diff
changeset
|
257 'ui.prompt': 'yellow', |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
258 'log.changeset': 'yellow', |
19214
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
259 'rebase.rebased': 'blue', |
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
260 'rebase.remaining': 'red bold', |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
261 'resolve.resolved': 'green bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
262 'resolve.unresolved': 'red bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
263 'status.added': 'green bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
264 'status.clean': 'none', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
265 'status.copied': 'none', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
266 'status.deleted': 'cyan bold underline', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
267 'status.ignored': 'black bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
268 'status.modified': 'blue bold', |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
269 'status.removed': 'red bold', |
15048
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
270 'status.unknown': 'magenta bold underline', |
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
271 'tags.normal': 'green', |
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
272 'tags.local': 'black bold'} |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
273 |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
274 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
275 def _effect_str(effect): |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
276 '''Helper function for render_effects().''' |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
277 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
278 bg = False |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
279 if effect.endswith('_background'): |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
280 bg = True |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
281 effect = effect[:-11] |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
282 attr, val = _terminfo_params[effect] |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
283 if attr: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
284 return curses.tigetstr(val) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
285 elif bg: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
286 return curses.tparm(curses.tigetstr('setab'), val) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
287 else: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
288 return curses.tparm(curses.tigetstr('setaf'), val) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
289 |
8622
0a4f6e1b78dc
color: use lists instead of tuples for effects
Martin Geisler <mg@lazybytes.net>
parents:
8278
diff
changeset
|
290 def render_effects(text, effects): |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
291 'Wrap text in commands to turn on each effect.' |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
292 if not text: |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
293 return text |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
294 if not _terminfo_params: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
295 start = [str(_effects[e]) for e in ['none'] + effects.split()] |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
296 start = '\033[' + ';'.join(start) + 'm' |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
297 stop = '\033[' + str(_effects['none']) + 'm' |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
298 else: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
299 start = ''.join(_effect_str(effect) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
300 for effect in ['none'] + effects.split()) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
301 stop = _effect_str('none') |
7459
3fb5c142a9f0
color: replace effect-specific reset control codes with general purpose one
Brodie Rao <me+hg@dackz.net>
parents:
7457
diff
changeset
|
302 return ''.join([start, text, stop]) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
303 |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
304 def extstyles(): |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
305 for name, ext in extensions.extensions(): |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
306 _styles.update(getattr(ext, 'colortable', {})) |
7456 | 307 |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
308 def configstyles(ui): |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
309 for status, cfgeffects in ui.configitems('color'): |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
310 if '.' not in status or status.startswith('color.'): |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
311 continue |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
312 cfgeffects = ui.configlist('color', status) |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
313 if cfgeffects: |
8945
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
314 good = [] |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
315 for e in cfgeffects: |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
316 if not _terminfo_params and e in _effects: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
317 good.append(e) |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
318 elif e in _terminfo_params or e[:-11] in _terminfo_params: |
8945
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
319 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
|
320 else: |
7b3d837ca60e
color: don't blow up if configured with unknown color (just warn).
Greg Ward <greg-hg@gerg.ca>
parents:
8894
diff
changeset
|
321 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
|
322 "(configured in color.%s)\n") |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
323 % (e, status)) |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
324 _styles[status] = ' '.join(good) |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
325 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
326 class colorui(uimod.ui): |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
327 def popbuffer(self, labeled=False): |
19072
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
328 if self._colormode is None: |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
329 return super(colorui, self).popbuffer(labeled) |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
330 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
331 if labeled: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
332 return ''.join(self.label(a, label) for a, label |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
333 in self._buffers.pop()) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
334 return ''.join(a for a, label in self._buffers.pop()) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
335 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
336 _colormode = 'ansi' |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
337 def write(self, *args, **opts): |
19072
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
338 if self._colormode is None: |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
339 return super(colorui, self).write(*args, **opts) |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
340 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
341 label = opts.get('label', '') |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
342 if self._buffers: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
343 self._buffers[-1].extend([(str(a), label) for a in args]) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
344 elif self._colormode == 'win32': |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
345 for a in args: |
11727
c34a1ab80550
color: pass write/write_err to win32print correctly (issue2312)
Brodie Rao <brodie@bitheap.org>
parents:
11555
diff
changeset
|
346 win32print(a, super(colorui, self).write, **opts) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
347 else: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
348 return super(colorui, self).write( |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
349 *[self.label(str(a), label) for a in args], **opts) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
350 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
351 def write_err(self, *args, **opts): |
19072
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
352 if self._colormode is None: |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
353 return super(colorui, self).write_err(*args, **opts) |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
354 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
355 label = opts.get('label', '') |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
356 if self._colormode == 'win32': |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
357 for a in args: |
11727
c34a1ab80550
color: pass write/write_err to win32print correctly (issue2312)
Brodie Rao <brodie@bitheap.org>
parents:
11555
diff
changeset
|
358 win32print(a, super(colorui, self).write_err, **opts) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
359 else: |
11732
386e56ecfb78
color: call correct superclass method in write_err
Brodie Rao <brodie@bitheap.org>
parents:
11727
diff
changeset
|
360 return super(colorui, self).write_err( |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
361 *[self.label(str(a), label) for a in args], **opts) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
362 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
363 def label(self, msg, label): |
19072
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
364 if self._colormode is None: |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
365 return super(colorui, self).label(msg, label) |
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
366 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
367 effects = [] |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
368 for l in label.split(): |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
369 s = _styles.get(l, '') |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
370 if s: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
371 effects.append(s) |
14145
4b7e4b9db8fb
color: fix using multiple effects
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14139
diff
changeset
|
372 effects = ' '.join(effects) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
373 if effects: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
374 return '\n'.join([render_effects(s, effects) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
375 for s in msg.split('\n')]) |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
376 return msg |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
377 |
18290
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
378 def templatelabel(context, mapping, args): |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
379 if len(args) != 2: |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
380 # i18n: "label" is a keyword |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
381 raise error.ParseError(_("label expects two arguments")) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
382 |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
383 thing = templater.stringify(args[1][0](context, mapping, args[1][1])) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
384 thing = templater.runtemplate(context, mapping, |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
385 templater.compiletemplate(thing, context)) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
386 |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
387 # apparently, repo could be a string that is the favicon? |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
388 repo = mapping.get('repo', '') |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
389 if isinstance(repo, str): |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
390 return thing |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
391 |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
392 label = templater.stringify(args[0][0](context, mapping, args[0][1])) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
393 label = templater.runtemplate(context, mapping, |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
394 templater.compiletemplate(label, context)) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
395 |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
396 thing = templater.stringify(thing) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
397 label = templater.stringify(label) |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
398 |
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
399 return repo.ui.label(thing, label) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
400 |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
401 def uisetup(ui): |
10871 | 402 if ui.plain(): |
403 return | |
19063
7ae12ce87594
color: set the ui class in reposetup, before a repo is created
Simon Heimberg <simohe@besonet.ch>
parents:
18921
diff
changeset
|
404 if not issubclass(ui.__class__, colorui): |
7ae12ce87594
color: set the ui class in reposetup, before a repo is created
Simon Heimberg <simohe@besonet.ch>
parents:
18921
diff
changeset
|
405 colorui.__bases__ = (ui.__class__,) |
7ae12ce87594
color: set the ui class in reposetup, before a repo is created
Simon Heimberg <simohe@besonet.ch>
parents:
18921
diff
changeset
|
406 ui.__class__ = colorui |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
407 def colorcmd(orig, ui_, opts, cmd, cmdfunc): |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
408 mode = _modesetup(ui_, opts) |
19073
d78d0256198e
color: set _colormode to None when mode is unset (issue3895)
Siddharth Agarwal <sid0@fb.com>
parents:
19072
diff
changeset
|
409 colorui._colormode = mode |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
410 if mode: |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
411 extstyles() |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
412 configstyles(ui_) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
413 return orig(ui_, opts, cmd, cmdfunc) |
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
414 extensions.wrapfunction(dispatch, '_runcommand', colorcmd) |
18290
323e1267de36
color: add template label function
Sean Farley <sean.michael.farley@gmail.com>
parents:
17806
diff
changeset
|
415 templater.funcs['label'] = templatelabel |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
416 |
12693
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
417 def extsetup(ui): |
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
418 commands.globalopts.append( |
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
419 ('', 'color', 'auto', |
12807
6bbf0139a36d
color: give hint to translators about untranslated keywords
Martin Geisler <mg@lazybytes.net>
parents:
12693
diff
changeset
|
420 # i18n: 'always', 'auto', and 'never' are keywords and should |
6bbf0139a36d
color: give hint to translators about untranslated keywords
Martin Geisler <mg@lazybytes.net>
parents:
12693
diff
changeset
|
421 # not be translated |
12693
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
422 _("when to colorize (boolean, always, auto, or never)"), |
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
423 _('TYPE'))) |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
424 |
13641
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
425 if os.name != 'nt': |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
426 w32effects = None |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
427 else: |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
428 import re, ctypes |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
429 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
430 _kernel32 = ctypes.windll.kernel32 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
431 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
432 _WORD = ctypes.c_ushort |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
433 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
434 _INVALID_HANDLE_VALUE = -1 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
435 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
436 class _COORD(ctypes.Structure): |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
437 _fields_ = [('X', ctypes.c_short), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
438 ('Y', ctypes.c_short)] |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
439 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
440 class _SMALL_RECT(ctypes.Structure): |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
441 _fields_ = [('Left', ctypes.c_short), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
442 ('Top', ctypes.c_short), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
443 ('Right', ctypes.c_short), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
444 ('Bottom', ctypes.c_short)] |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
445 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
446 class _CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure): |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
447 _fields_ = [('dwSize', _COORD), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
448 ('dwCursorPosition', _COORD), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
449 ('wAttributes', _WORD), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
450 ('srWindow', _SMALL_RECT), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
451 ('dwMaximumWindowSize', _COORD)] |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
452 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
453 _STD_OUTPUT_HANDLE = 0xfffffff5L # (DWORD)-11 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
454 _STD_ERROR_HANDLE = 0xfffffff4L # (DWORD)-12 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
455 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
456 _FOREGROUND_BLUE = 0x0001 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
457 _FOREGROUND_GREEN = 0x0002 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
458 _FOREGROUND_RED = 0x0004 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
459 _FOREGROUND_INTENSITY = 0x0008 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
460 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
461 _BACKGROUND_BLUE = 0x0010 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
462 _BACKGROUND_GREEN = 0x0020 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
463 _BACKGROUND_RED = 0x0040 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
464 _BACKGROUND_INTENSITY = 0x0080 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
465 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
466 _COMMON_LVB_REVERSE_VIDEO = 0x4000 |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
467 _COMMON_LVB_UNDERSCORE = 0x8000 |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
468 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
469 # http://msdn.microsoft.com/en-us/library/ms682088%28VS.85%29.aspx |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
470 w32effects = { |
12277
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
471 'none': -1, |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
472 'black': 0, |
13641
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
473 'red': _FOREGROUND_RED, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
474 'green': _FOREGROUND_GREEN, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
475 'yellow': _FOREGROUND_RED | _FOREGROUND_GREEN, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
476 'blue': _FOREGROUND_BLUE, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
477 'magenta': _FOREGROUND_BLUE | _FOREGROUND_RED, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
478 'cyan': _FOREGROUND_BLUE | _FOREGROUND_GREEN, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
479 'white': _FOREGROUND_RED | _FOREGROUND_GREEN | _FOREGROUND_BLUE, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
480 'bold': _FOREGROUND_INTENSITY, |
12278 | 481 'black_background': 0x100, # unused value > 0x0f |
13641
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
482 'red_background': _BACKGROUND_RED, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
483 'green_background': _BACKGROUND_GREEN, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
484 'yellow_background': _BACKGROUND_RED | _BACKGROUND_GREEN, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
485 'blue_background': _BACKGROUND_BLUE, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
486 'purple_background': _BACKGROUND_BLUE | _BACKGROUND_RED, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
487 'cyan_background': _BACKGROUND_BLUE | _BACKGROUND_GREEN, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
488 'white_background': (_BACKGROUND_RED | _BACKGROUND_GREEN | |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
489 _BACKGROUND_BLUE), |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
490 'bold_background': _BACKGROUND_INTENSITY, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
491 'underline': _COMMON_LVB_UNDERSCORE, # double-byte charsets only |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
492 'inverse': _COMMON_LVB_REVERSE_VIDEO, # double-byte charsets only |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
493 } |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
494 |
13641
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
495 passthrough = set([_FOREGROUND_INTENSITY, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
496 _BACKGROUND_INTENSITY, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
497 _COMMON_LVB_UNDERSCORE, |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
498 _COMMON_LVB_REVERSE_VIDEO]) |
12277
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
499 |
13641
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
500 stdout = _kernel32.GetStdHandle( |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
501 _STD_OUTPUT_HANDLE) # don't close the handle returned |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
502 if stdout is None or stdout == _INVALID_HANDLE_VALUE: |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
503 w32effects = None |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
504 else: |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
505 csbi = _CONSOLE_SCREEN_BUFFER_INFO() |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
506 if not _kernel32.GetConsoleScreenBufferInfo( |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
507 stdout, ctypes.byref(csbi)): |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
508 # stdout may not support GetConsoleScreenBufferInfo() |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
509 # when called from subprocess or redirected |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
510 w32effects = None |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
511 else: |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
512 origattr = csbi.wAttributes |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
513 ansire = re.compile('\033\[([^m]*)m([^\033]*)(.*)', |
2420cb1ea1d6
color: port to using ctypes (issue2687)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13635
diff
changeset
|
514 re.MULTILINE | re.DOTALL) |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
515 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
516 def win32print(text, orig, **opts): |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
517 label = opts.get('label', '') |
12277
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
518 attr = origattr |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
519 |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
520 def mapcolor(val, attr): |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
521 if val == -1: |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
522 return origattr |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
523 elif val in passthrough: |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
524 return attr | val |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
525 elif val > 0x0f: |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
526 return (val & 0x70) | (attr & 0x8f) |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
527 else: |
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
528 return (val & 0x07) | (attr & 0xf8) |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
529 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
530 # determine console attributes based on labels |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
531 for l in label.split(): |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
532 style = _styles.get(l, '') |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
533 for effect in style.split(): |
12277
a7d3147bd4b3
color: add win32 support for non-black background
Sune Foldager <cryo@cyanite.org>
parents:
12083
diff
changeset
|
534 attr = mapcolor(w32effects[effect], attr) |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
535 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
536 # hack to ensure regexp finds data |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
537 if not text.startswith('\033['): |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
538 text = '\033[m' + text |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
539 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
540 # Look for ANSI-like codes embedded in text |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
541 m = re.match(ansire, text) |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
542 |
13919
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
543 try: |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
544 while m: |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
545 for sattr in m.group(1).split(';'): |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
546 if sattr: |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
547 attr = mapcolor(int(sattr), attr) |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
548 _kernel32.SetConsoleTextAttribute(stdout, attr) |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
549 orig(m.group(2), **opts) |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
550 m = re.match(ansire, m.group(3)) |
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
551 finally: |
17424
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
16743
diff
changeset
|
552 # Explicitly reset original attributes |
13919
67f20625703f
color: reset win32 console color in a finally block
Idan Kamara <idankk86@gmail.com>
parents:
13774
diff
changeset
|
553 _kernel32.SetConsoleTextAttribute(stdout, origattr) |