Mercurial > hg
annotate hgext/color.py @ 31085:3422de9b657e
color: extract the label code into its own function
We extract the logic into a function. This will allow us to move the logic into
the core 'color' module and later call it directly from core.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 23 Feb 2017 19:00:26 +0100 |
parents | 1482b57701ad |
children | e6082078c853 |
rev | line source |
---|---|
22771
d6274291fac1
color: update description of the extension
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22763
diff
changeset
|
1 # color.py color output for Mercurial commands |
5787
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 |
22771
d6274291fac1
color: update description of the extension
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22763
diff
changeset
|
10 The color extension colorizes output from several Mercurial commands. |
d6274291fac1
color: update description of the extension
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22763
diff
changeset
|
11 For example, the diff command shows additions in green and deletions |
d6274291fac1
color: update description of the extension
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22763
diff
changeset
|
12 in red, while the status command shows modified files in magenta. Many |
d6274291fac1
color: update description of the extension
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22763
diff
changeset
|
13 other commands have analogous colors. It is possible to customize |
d6274291fac1
color: update description of the extension
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22763
diff
changeset
|
14 these colors. |
7457
a70fb83cbb9e
diff colorization: finish highlighting trailing whitespace
Georg Brandl <georg@python.org>
parents:
7456
diff
changeset
|
15 |
22772
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
16 Effects |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
17 ------- |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
18 |
7988
0447939b4b97
color: word-wrap help texts at 70 characters
Martin Geisler <mg@daimi.au.dk>
parents:
7983
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 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
|
23 function (aka ANSI escape codes). |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
24 |
22772
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
25 The available effects in terminfo mode are 'blink', 'bold', 'dim', |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
26 'inverse', 'invisible', 'italic', 'standout', and 'underline'; in |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
27 ECMA-48 mode, the options are 'bold', 'inverse', 'italic', and |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
28 'underline'. How each is rendered depends on the terminal emulator. |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
29 Some may not be available for a given terminal type, and will be |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
30 silently ignored. |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
31 |
30176
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
32 If the terminfo entry for your terminal is missing codes for an effect |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
33 or has the wrong codes, you can add or override those codes in your |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
34 configuration:: |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
35 |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
36 [color] |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
37 terminfo.dim = \E[2m |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
38 |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
39 where '\E' is substituted with an escape character. |
9f41b66cffc0
color: add some documentation for custom terminfo codes
Danek Duvall <danek.duvall@oracle.com>
parents:
30175
diff
changeset
|
40 |
22772
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
41 Labels |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
42 ------ |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
43 |
22462
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
44 Text receives color effects depending on the labels that it has. Many |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
45 default Mercurial commands emit labelled text. You can also define |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
46 your own labels in templates using the label function, see :hg:`help |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
47 templates`. A single portion of text may have more than one label. In |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
48 that case, effects given to the last label will override any other |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
49 effects. This includes the special "none" effect, which nullifies |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
50 other effects. |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
51 |
22463
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
52 Labels are normally invisible. In order to see these labels and their |
22711
60ac52a21512
color: update docstring for debug option
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22710
diff
changeset
|
53 position in the text, use the global --color=debug option. The same |
60ac52a21512
color: update docstring for debug option
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22710
diff
changeset
|
54 anchor text may be associated to multiple labels, e.g. |
22463
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
55 |
22711
60ac52a21512
color: update docstring for debug option
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22710
diff
changeset
|
56 [log.changeset changeset.secret|changeset: 22611:6f0a53c8f587] |
22463
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
57 |
22462
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
58 The following are the default effects for some default labels. Default |
fbd67cf34799
color: document that labels are used for colorizing text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21991
diff
changeset
|
59 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
|
60 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
61 [color] |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
62 status.modified = blue bold underline red_background |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
63 status.added = green bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
64 status.removed = red bold blue_background |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
65 status.deleted = cyan bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
66 status.unknown = magenta bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
67 status.ignored = black bold |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
68 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
69 # 'none' turns off all effects |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
70 status.clean = none |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
71 status.copied = none |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
72 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
73 qseries.applied = blue bold underline |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
74 qseries.unapplied = black bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
75 qseries.missing = red bold |
7456 | 76 |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
77 diff.diffline = bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
78 diff.extended = cyan bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
79 diff.file_a = red bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
80 diff.file_b = green bold |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
81 diff.hunk = magenta |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
82 diff.deleted = red |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
83 diff.inserted = green |
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
84 diff.changed = white |
22710
b07fd3ac8882
color: document the possibility to colourise tabs in diffs
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22465
diff
changeset
|
85 diff.tab = |
9206
c1a1b49221e3
color: use reST syntax for literal block
Martin Geisler <mg@lazybytes.net>
parents:
9057
diff
changeset
|
86 diff.trailingwhitespace = bold red_background |
10046
0c23b0b3516b
color: Add support for bookmarks
David Soria Parra <dsp@php.net>
parents:
10045
diff
changeset
|
87 |
22465
f8e2aebbb24c
color: document that changeset phases have labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22464
diff
changeset
|
88 # Blank so it inherits the style of the surrounding label |
f8e2aebbb24c
color: document that changeset phases have labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22464
diff
changeset
|
89 changeset.public = |
f8e2aebbb24c
color: document that changeset phases have labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22464
diff
changeset
|
90 changeset.draft = |
f8e2aebbb24c
color: document that changeset phases have labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22464
diff
changeset
|
91 changeset.secret = |
f8e2aebbb24c
color: document that changeset phases have labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22464
diff
changeset
|
92 |
10223
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
93 resolve.unresolved = red bold |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
94 resolve.resolved = green bold |
51421ab573de
color: colorize output of hg resolve -l
Georg Brandl <georg@python.org>
parents:
10222
diff
changeset
|
95 |
25347
ceec79b5657a
bookmarks: name label for active bookmark correctly
Ryan McElroy <rmcelroy@fb.com>
parents:
25186
diff
changeset
|
96 bookmarks.active = green |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
97 |
11969
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
98 branches.active = none |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
99 branches.closed = black bold |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
100 branches.current = green |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
101 branches.inactive = none |
52ec5c813723
color: enable branches support
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
11750
diff
changeset
|
102 |
15048
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
103 tags.normal = green |
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
104 tags.local = black bold |
2f0a3977c939
color: add styles for tags
Marc Simpson <marc@0branch.com>
parents:
14989
diff
changeset
|
105 |
19214
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
106 rebase.rebased = blue |
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
107 rebase.remaining = red bold |
0250047a365e
summary: indicate if a rebase is underway
Bryan O'Sullivan <bryano@fb.com>
parents:
19073
diff
changeset
|
108 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
19298
diff
changeset
|
109 shelve.age = cyan |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
19298
diff
changeset
|
110 shelve.newest = green bold |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
19298
diff
changeset
|
111 shelve.name = blue bold |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
19298
diff
changeset
|
112 |
19215
f184fe1e2ac5
summary: add a histedit hook
Bryan O'Sullivan <bryano@fb.com>
parents:
19214
diff
changeset
|
113 histedit.remaining = red bold |
f184fe1e2ac5
summary: add a histedit hook
Bryan O'Sullivan <bryano@fb.com>
parents:
19214
diff
changeset
|
114 |
22772
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
115 Custom colors |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
116 ------------- |
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
|
117 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
122 color.brightblue = 12 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
123 color.pink = 207 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
124 color.orange = 202 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
125 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
126 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
|
127 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
|
128 '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
|
129 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
|
130 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
|
131 |
22772
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
132 Modes |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
133 ----- |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
134 |
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
|
135 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
|
136 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
|
137 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
|
138 |
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
139 [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
|
140 mode = terminfo |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
141 |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
142 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
|
143 disable color. |
22772
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
144 |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
145 Note that on some systems, terminfo mode may cause problems when using |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
146 color with the pager extension and less -R. less with the -R option |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
147 will only display ECMA-48 color codes, and terminfo mode may sometimes |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
148 emit codes that less doesn't understand. You can work around this by |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
149 either using ansi mode (or auto mode), or by using less -r (which will |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
150 pass through all terminal control codes, not just color control |
b186b3ef4b54
color: reorganise and sectionify the help text
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22771
diff
changeset
|
151 codes). |
24068
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
152 |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
153 On some systems (such as MSYS in Windows), the terminal may support |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
154 a different color mode than the pager (activated via the "pager" |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
155 extension). It is possible to define separate modes depending on whether |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
156 the pager is active:: |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
157 |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
158 [color] |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
159 mode = auto |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
160 pagermode = ansi |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
161 |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
162 If ``pagermode`` is not defined, the ``mode`` will be used. |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
163 ''' |
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
164 |
28968
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
165 from __future__ import absolute_import |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
166 |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
167 try: |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
168 import curses |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
169 curses.COLOR_BLACK # force import |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
170 except ImportError: |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
171 curses = None |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
172 |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28968
diff
changeset
|
173 from mercurial.i18n import _ |
28968
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
174 from mercurial import ( |
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
175 cmdutil, |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
176 color, |
28968
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
177 commands, |
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
178 dispatch, |
30638
1c5cbf28f007
py3: replace os.environ with encoding.environ (part 5 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30387
diff
changeset
|
179 encoding, |
28968
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
180 extensions, |
30640
7a3e67bfa417
py3: replace os.name with pycompat.osname (part 2 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30638
diff
changeset
|
181 pycompat, |
28968
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
182 subrepo, |
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
183 ui as uimod, |
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
184 util, |
a5d449a7bc8f
py3: make color use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28633
diff
changeset
|
185 ) |
5787
b7b22a2ade2e
Add colored output to status and qseries commands
Kevin Christen <kevin.christen@gmail.com>
parents:
diff
changeset
|
186 |
21249
2b8697e20978
color: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21227
diff
changeset
|
187 cmdtable = {} |
2b8697e20978
color: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21227
diff
changeset
|
188 command = cmdutil.command(cmdtable) |
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29205
diff
changeset
|
189 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24848
diff
changeset
|
190 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24848
diff
changeset
|
191 # be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24848
diff
changeset
|
192 # leave the attribute unspecified. |
29841
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29205
diff
changeset
|
193 testedwith = 'ships-with-hg-core' |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
15771
diff
changeset
|
194 |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
195 def _terminfosetup(ui, mode): |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
196 '''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
|
197 |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
198 # If we failed to load curses, we go ahead and return. |
31068
27d3bc0c9093
color: make a test for curse availability explicite
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31067
diff
changeset
|
199 if curses is None: |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
200 return |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
201 # 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
|
202 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
|
203 return |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
204 |
31069
cf2bc3792ef4
color: minor simplification of some terminfo setup code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31068
diff
changeset
|
205 for key, val in ui.configitems('color'): |
cf2bc3792ef4
color: minor simplification of some terminfo setup code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31068
diff
changeset
|
206 if key.startswith('color.'): |
cf2bc3792ef4
color: minor simplification of some terminfo setup code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31068
diff
changeset
|
207 newval = (False, int(val), '') |
cf2bc3792ef4
color: minor simplification of some terminfo setup code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31068
diff
changeset
|
208 color._terminfo_params[key[6:]] = newval |
31070
ebd14a4b03fc
color: merge two identical 'for' loops
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31069
diff
changeset
|
209 elif key.startswith('terminfo.'): |
31069
cf2bc3792ef4
color: minor simplification of some terminfo setup code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31068
diff
changeset
|
210 newval = (True, '', val.replace('\\E', '\x1b')) |
cf2bc3792ef4
color: minor simplification of some terminfo setup code
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31068
diff
changeset
|
211 color._terminfo_params[key[9:]] = newval |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
212 try: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
213 curses.setupterm() |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25597
diff
changeset
|
214 except curses.error as e: |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
215 color._terminfo_params.clear() |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
216 return |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
217 |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
218 for key, (b, e, c) in color._terminfo_params.items(): |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
219 if not b: |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
220 continue |
30173
f34a8cff51d9
color: allow for user-configurable terminfo codes for effects
Danek Duvall <danek.duvall@oracle.com>
parents:
29890
diff
changeset
|
221 if not c and not curses.tigetstr(e): |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
222 # 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
|
223 # noisy and use ui.debug(). |
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
224 ui.debug("no terminfo entry for %s\n" % e) |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
225 del color._terminfo_params[key] |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
226 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
|
227 # 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
|
228 # 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
|
229 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
|
230 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
|
231 "ECMA-48 color\n")) |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
232 color._terminfo_params.clear() |
13987
e0f07847f8de
color: add support for terminfo-based attributes and color
Danek Duvall <duvall@comfychair.org>
parents:
13919
diff
changeset
|
233 |
19297
8ddc3cd962ba
color: only provide the required opt to _modesetup
Simon Heimberg <simohe@besonet.ch>
parents:
19215
diff
changeset
|
234 def _modesetup(ui, coloropt): |
22463
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
235 if coloropt == 'debug': |
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
236 return 'debug' |
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
237 |
21723
35eb333d61d5
color: add parenthesis to help readability
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21249
diff
changeset
|
238 auto = (coloropt == 'auto') |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
239 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
|
240 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
|
241 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
242 |
30638
1c5cbf28f007
py3: replace os.environ with encoding.environ (part 5 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30387
diff
changeset
|
243 formatted = (always or (encoding.environ.get('TERM') != 'dumb' |
1c5cbf28f007
py3: replace os.environ with encoding.environ (part 5 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30387
diff
changeset
|
244 and ui.formatted())) |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
245 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
246 mode = ui.config('color', 'mode', 'auto') |
24068
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
247 |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
248 # If pager is active, color.pagermode overrides color.mode. |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
249 if getattr(ui, 'pageractive', False): |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
250 mode = ui.config('color', 'pagermode', mode) |
4e02418b4236
color: support a different color mode when the pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24028
diff
changeset
|
251 |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
252 realmode = mode |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
253 if mode == 'auto': |
30640
7a3e67bfa417
py3: replace os.name with pycompat.osname (part 2 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30638
diff
changeset
|
254 if pycompat.osname == 'nt': |
30638
1c5cbf28f007
py3: replace os.environ with encoding.environ (part 5 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30387
diff
changeset
|
255 term = encoding.environ.get('TERM') |
24028
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
256 # TERM won't be defined in a vanilla cmd.exe environment. |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
257 |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
258 # UNIX-like environments on Windows such as Cygwin and MSYS will |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
259 # set TERM. They appear to make a best effort attempt at setting it |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
260 # to something appropriate. However, not all environments with TERM |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
261 # defined support ANSI. Since "ansi" could result in terminal |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
262 # gibberish, we error on the side of selecting "win32". However, if |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
263 # w32effects is not defined, we almost certainly don't support |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
264 # "win32", so don't even try. |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
265 if (term and 'xterm' in term) or not color.w32effects: |
24028
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
266 realmode = 'ansi' |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
267 else: |
a78888d98606
color: be more conservative about setting ANSI mode on Windows (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23925
diff
changeset
|
268 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
|
269 else: |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
270 realmode = 'ansi' |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
271 |
24266
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
272 def modewarn(): |
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
273 # only warn if color.mode was explicitly set and we're in |
30367
e193870eb680
color: show mode warning based on ui.formatted
Xidorn Quan <me@upsuper.org>
parents:
30286
diff
changeset
|
274 # a formatted terminal |
e193870eb680
color: show mode warning based on ui.formatted
Xidorn Quan <me@upsuper.org>
parents:
30286
diff
changeset
|
275 if mode == realmode and ui.formatted(): |
24266
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
276 ui.warn(_('warning: failed to set color mode to %s\n') % mode) |
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
277 |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
278 if realmode == 'win32': |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
279 color._terminfo_params.clear() |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
280 if not color.w32effects: |
24266
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
281 modewarn() |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
282 return None |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
283 color._effects.update(color.w32effects) |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
284 elif realmode == 'ansi': |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
285 color._terminfo_params.clear() |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
286 elif realmode == 'terminfo': |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
287 _terminfosetup(ui, mode) |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
288 if not color._terminfo_params: |
24266
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
289 ## FIXME Shouldn't we return None in this case too? |
c14b1d349af3
color: consolidate cut-and-paste code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24249
diff
changeset
|
290 modewarn() |
14495
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
291 realmode = 'ansi' |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
292 else: |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
293 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
294 |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
295 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
|
296 return realmode |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
297 return None |
ad6ad51cc0dd
color: fix --color=always when output is piped
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14145
diff
changeset
|
298 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
299 class colorui(uimod.ui): |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
300 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
|
301 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
|
302 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
|
303 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
304 label = opts.get('label', '') |
28633
e35d7f131483
ui: add prompt argument to write (issue5154) (API)
timeless <timeless@mozdev.org>
parents:
28374
diff
changeset
|
305 if self._buffers and not opts.get('prompt', False): |
27108
717b75ae5bb0
color: evaluate labels at write time
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
306 if self._bufferapplylabels: |
27110
f04bd381e8c0
ui: avoid needless casting to a str
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27109
diff
changeset
|
307 self._buffers[-1].extend(self.label(a, label) for a in args) |
27108
717b75ae5bb0
color: evaluate labels at write time
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
308 else: |
27110
f04bd381e8c0
ui: avoid needless casting to a str
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27109
diff
changeset
|
309 self._buffers[-1].extend(args) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
310 elif self._colormode == 'win32': |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
311 for a in args: |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
312 color.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
|
313 else: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
314 return super(colorui, self).write( |
27110
f04bd381e8c0
ui: avoid needless casting to a str
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27109
diff
changeset
|
315 *[self.label(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
|
316 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
321 label = opts.get('label', '') |
24848
2f88821856eb
ui: allow capture of subprocess output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24535
diff
changeset
|
322 if self._bufferstates and self._bufferstates[-1][0]: |
21190
2606e7f227f6
color: add missing handling of stderr capture introduced by 350dc24a553d
Yuya Nishihara <yuya@tcha.org>
parents:
21037
diff
changeset
|
323 return self.write(*args, **opts) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
324 if self._colormode == 'win32': |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
325 for a in args: |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
326 color.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
|
327 else: |
11732
386e56ecfb78
color: call correct superclass method in write_err
Brodie Rao <brodie@bitheap.org>
parents:
11727
diff
changeset
|
328 return super(colorui, self).write_err( |
27110
f04bd381e8c0
ui: avoid needless casting to a str
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27109
diff
changeset
|
329 *[self.label(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
|
330 |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
331 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
|
332 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
|
333 return super(colorui, self).label(msg, label) |
31085
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
334 return colorlabel(self, msg, label) |
19072
b7b50a54bec9
color: turn colorui functions into forwards when color is None
Siddharth Agarwal <sid0@fb.com>
parents:
19063
diff
changeset
|
335 |
31085
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
336 def colorlabel(ui, msg, label): |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
337 """add color control code according to the mode""" |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
338 if ui._colormode == 'debug': |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
339 if label and msg: |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
340 if msg[-1] == '\n': |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
341 msg = "[%s|%s]\n" % (label, msg[:-1]) |
31084
1482b57701ad
color: inline the 'showlabel' method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31083
diff
changeset
|
342 else: |
31085
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
343 msg = "[%s|%s]" % (label, msg) |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
344 elif ui._colormode is not None: |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
345 effects = [] |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
346 for l in label.split(): |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
347 s = color._styles.get(l, '') |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
348 if s: |
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
349 effects.append(s) |
30969
ddc80d1777a6
color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30968
diff
changeset
|
350 elif color.valideffect(l): |
20993
a8db48e997b5
color: fallback and test label as an effect
Sean Farley <sean.michael.farley@gmail.com>
parents:
20992
diff
changeset
|
351 effects.append(l) |
14145
4b7e4b9db8fb
color: fix using multiple effects
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
14139
diff
changeset
|
352 effects = ' '.join(effects) |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
353 if effects: |
31085
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
354 msg = '\n'.join([color._render_effects(line, effects) |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
355 for line in msg.split('\n')]) |
3422de9b657e
color: extract the label code into its own function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31084
diff
changeset
|
356 return msg |
11555
d8d0fc3988ca
color/progress: subclass ui instead of using wrapfunction (issue2096)
Brodie Rao <brodie@bitheap.org>
parents:
11326
diff
changeset
|
357 |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
358 def uisetup(ui): |
10871 | 359 if ui.plain(): |
360 return | |
19298
6cd8403e070f
color: use pythons isinstance method instead of reprogramming it
Simon Heimberg <simohe@besonet.ch>
parents:
19297
diff
changeset
|
361 if not isinstance(ui, colorui): |
19063
7ae12ce87594
color: set the ui class in reposetup, before a repo is created
Simon Heimberg <simohe@besonet.ch>
parents:
18921
diff
changeset
|
362 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
|
363 ui.__class__ = colorui |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
364 def colorcmd(orig, ui_, opts, cmd, cmdfunc): |
19297
8ddc3cd962ba
color: only provide the required opt to _modesetup
Simon Heimberg <simohe@besonet.ch>
parents:
19215
diff
changeset
|
365 mode = _modesetup(ui_, opts['color']) |
19073
d78d0256198e
color: set _colormode to None when mode is unset (issue3895)
Siddharth Agarwal <sid0@fb.com>
parents:
19072
diff
changeset
|
366 colorui._colormode = mode |
22463
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
367 if mode and mode != 'debug': |
30971
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30969
diff
changeset
|
368 color.configstyles(ui_) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
369 return orig(ui_, opts, cmd, cmdfunc) |
23780
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
370 def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None): |
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
371 if gitsub.ui._colormode and len(commands) and commands[0] == "diff": |
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
372 # insert the argument in the front, |
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
373 # the end of git diff arguments is used for paths |
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
374 commands.insert(1, '--color') |
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
375 return orig(gitsub, commands, env, stream, cwd) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
376 extensions.wrapfunction(dispatch, '_runcommand', colorcmd) |
23780
a857755144dc
color: add support for colorizing git subrepo diffs
Mathias De Maré <mathias.demare@gmail.com>
parents:
23173
diff
changeset
|
377 extensions.wrapfunction(subrepo.gitsubrepo, '_gitnodir', colorgit) |
10826
717c35d55fb3
color: colorize based on output labels instead of parsing output
Brodie Rao <brodie@bitheap.org>
parents:
10477
diff
changeset
|
378 |
12693
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
379 def extsetup(ui): |
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
380 commands.globalopts.append( |
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
381 ('', 'color', 'auto', |
22463
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
382 # i18n: 'always', 'auto', 'never', and 'debug' are keywords |
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
383 # and should not be translated |
1c4ae0f6a30f
color: enable debug option to show labels
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22462
diff
changeset
|
384 _("when to colorize (boolean, always, auto, never, or debug)"), |
12693
33f0682ba8b1
color: add global option in extsetup() instead of globally
Brodie Rao <brodie@bitheap.org>
parents:
12278
diff
changeset
|
385 _('TYPE'))) |
10870
a4944b430417
color: add support for Windows consoles
Steve Borho <steve@borho.org>
parents:
10869
diff
changeset
|
386 |
30286
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
387 @command('debugcolor', |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
388 [('', 'style', None, _('show all configured styles'))], |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
389 'hg debugcolor') |
20455
a2c08adbb86e
color: add debugcolor command (issue4094)
Olle Lundberg <geek@nerd.sh>
parents:
20067
diff
changeset
|
390 def debugcolor(ui, repo, **opts): |
30286
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
391 """show available color, effects or style""" |
30284
7556507f7197
color: extract color and effect display from 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30283
diff
changeset
|
392 ui.write(('color mode: %s\n') % ui._colormode) |
30286
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
393 if opts.get('style'): |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
394 return _debugdisplaystyle(ui) |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
395 else: |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
396 return _debugdisplaycolor(ui) |
30284
7556507f7197
color: extract color and effect display from 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30283
diff
changeset
|
397 |
7556507f7197
color: extract color and effect display from 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30283
diff
changeset
|
398 def _debugdisplaycolor(ui): |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
399 oldstyle = color._styles.copy() |
30283
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
400 try: |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
401 color._styles.clear() |
30967
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30966
diff
changeset
|
402 for effect in color._effects.keys(): |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
403 color._styles[effect] = effect |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
404 if color._terminfo_params: |
30283
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
405 for k, v in ui.configitems('color'): |
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
406 if k.startswith('color.'): |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
407 color._styles[k] = k[6:] |
30283
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
408 elif k.startswith('terminfo.'): |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
409 color._styles[k] = k[9:] |
30283
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
410 ui.write(_('available colors:\n')) |
30285
bb2dfc0ea5b4
color: sort output of 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30284
diff
changeset
|
411 # sort label with a '_' after the other to group '_background' entry. |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
412 items = sorted(color._styles.items(), |
30285
bb2dfc0ea5b4
color: sort output of 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30284
diff
changeset
|
413 key=lambda i: ('_' in i[0], i[0], i[1])) |
bb2dfc0ea5b4
color: sort output of 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30284
diff
changeset
|
414 for colorname, label in items: |
30283
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
415 ui.write(('%s\n') % colorname, label=label) |
e1f6898a80e1
color: restore _style global after debugcolor ran
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30282
diff
changeset
|
416 finally: |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
417 color._styles.clear() |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
418 color._styles.update(oldstyle) |
20455
a2c08adbb86e
color: add debugcolor command (issue4094)
Olle Lundberg <geek@nerd.sh>
parents:
20067
diff
changeset
|
419 |
30286
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
420 def _debugdisplaystyle(ui): |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
421 ui.write(_('available style:\n')) |
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
422 width = max(len(s) for s in color._styles) |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30651
diff
changeset
|
423 for label, effects in sorted(color._styles.items()): |
30286
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
424 ui.write('%s' % label, label=label) |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
425 if effects: |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
426 # 50 |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
427 ui.write(': ') |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
428 ui.write(' ' * (max(0, width - len(label)))) |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
429 ui.write(', '.join(ui.label(e, e) for e in effects.split())) |
d44c407a5999
color: add the ability to display configured style to 'debugcolor'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30285
diff
changeset
|
430 ui.write('\n') |