Mercurial > hg
annotate mercurial/color.py @ 32078:bf5e13e38390 stable
pager: use less as a fallback on Unix
This seems reasonable choice per discussion, and the default-default of Git.
See also the inline-comment for why.
https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-April/097042.html
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 28 Apr 2017 20:51:14 +0900 |
parents | 8b7f794d6a9d |
children | 9a85ea1daf49 |
rev | line source |
---|---|
30652
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 # utility for color output for Mercurial commands |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 # |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> and other |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 # |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
7 |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
9 |
31521
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
10 import re |
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
11 |
30971
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
12 from .i18n import _ |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
13 |
31101
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
14 from . import ( |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
15 encoding, |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
16 pycompat, |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
17 util |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
18 ) |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
19 |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
20 try: |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
21 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
|
22 # Mapping from effect name to terminfo attribute name (or raw code) or |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
23 # color number. This will also force-load the curses module. |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
24 _baseterminfoparams = { |
31109
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
25 'none': (True, 'sgr0', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
26 'standout': (True, 'smso', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
27 'underline': (True, 'smul', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
28 'reverse': (True, 'rev', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
29 'inverse': (True, 'rev', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
30 'blink': (True, 'blink', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
31 'dim': (True, 'dim', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
32 'bold': (True, 'bold', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
33 'invisible': (True, 'invis', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
34 'italic': (True, 'sitm', ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
35 'black': (False, curses.COLOR_BLACK, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
36 'red': (False, curses.COLOR_RED, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
37 'green': (False, curses.COLOR_GREEN, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
38 'yellow': (False, curses.COLOR_YELLOW, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
39 'blue': (False, curses.COLOR_BLUE, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
40 'magenta': (False, curses.COLOR_MAGENTA, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
41 'cyan': (False, curses.COLOR_CYAN, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
42 'white': (False, curses.COLOR_WHITE, ''), |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
43 } |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
44 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
|
45 curses = None |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
46 _baseterminfoparams = {} |
30968
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30967
diff
changeset
|
47 |
32027
8b7f794d6a9d
color: also enable by default on windows
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32026
diff
changeset
|
48 _enabledbydefault = True |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
49 |
30967
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30653
diff
changeset
|
50 # start and stop parameters for effects |
31109
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
51 _effects = { |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
52 'none': 0, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
53 'black': 30, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
54 'red': 31, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
55 'green': 32, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
56 'yellow': 33, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
57 'blue': 34, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
58 'magenta': 35, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
59 'cyan': 36, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
60 'white': 37, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
61 'bold': 1, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
62 'italic': 3, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
63 'underline': 4, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
64 'inverse': 7, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
65 'dim': 2, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
66 'black_background': 40, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
67 'red_background': 41, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
68 'green_background': 42, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
69 'yellow_background': 43, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
70 'blue_background': 44, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
71 'purple_background': 45, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
72 'cyan_background': 46, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
73 'white_background': 47, |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
74 } |
30967
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30653
diff
changeset
|
75 |
31116
6483e49204ee
color: rename '_styles' to '_defaultstyles' for clarity
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31115
diff
changeset
|
76 _defaultstyles = { |
31109
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
77 'grep.match': 'red bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
78 'grep.linenumber': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
79 'grep.rev': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
80 'grep.change': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
81 'grep.sep': 'cyan', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
82 'grep.filename': 'magenta', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
83 'grep.user': 'magenta', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
84 'grep.date': 'magenta', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
85 'bookmarks.active': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
86 'branches.active': 'none', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
87 'branches.closed': 'black bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
88 'branches.current': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
89 'branches.inactive': 'none', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
90 'diff.changed': 'white', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
91 'diff.deleted': 'red', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
92 'diff.diffline': 'bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
93 'diff.extended': 'cyan bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
94 'diff.file_a': 'red bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
95 'diff.file_b': 'green bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
96 'diff.hunk': 'magenta', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
97 'diff.inserted': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
98 'diff.tab': '', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
99 'diff.trailingwhitespace': 'bold red_background', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
100 'changeset.public' : '', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
101 'changeset.draft' : '', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
102 'changeset.secret' : '', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
103 'diffstat.deleted': 'red', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
104 'diffstat.inserted': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
105 'histedit.remaining': 'red bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
106 'ui.prompt': 'yellow', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
107 'log.changeset': 'yellow', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
108 'patchbomb.finalsummary': '', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
109 'patchbomb.from': 'magenta', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
110 'patchbomb.to': 'cyan', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
111 'patchbomb.subject': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
112 'patchbomb.diffstats': '', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
113 'rebase.rebased': 'blue', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
114 'rebase.remaining': 'red bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
115 'resolve.resolved': 'green bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
116 'resolve.unresolved': 'red bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
117 'shelve.age': 'cyan', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
118 'shelve.newest': 'green bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
119 'shelve.name': 'blue bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
120 'status.added': 'green bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
121 'status.clean': 'none', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
122 'status.copied': 'none', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
123 'status.deleted': 'cyan bold underline', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
124 'status.ignored': 'black bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
125 'status.modified': 'blue bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
126 'status.removed': 'red bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
127 'status.unknown': 'magenta bold underline', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
128 'tags.normal': 'green', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
129 'tags.local': 'black bold', |
53230c5bb273
color: reinvent dictionary
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31106
diff
changeset
|
130 } |
30653
b2be4ccaff1d
color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30652
diff
changeset
|
131 |
b2be4ccaff1d
color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30652
diff
changeset
|
132 def loadcolortable(ui, extname, colortable): |
31116
6483e49204ee
color: rename '_styles' to '_defaultstyles' for clarity
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31115
diff
changeset
|
133 _defaultstyles.update(colortable) |
30969
ddc80d1777a6
color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30968
diff
changeset
|
134 |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
135 def _terminfosetup(ui, mode): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
136 '''Initialize terminfo data and the terminal if we're in terminfo mode.''' |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
137 |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
138 # If we failed to load curses, we go ahead and return. |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
139 if curses is None: |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
140 return |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
141 # Otherwise, see what the config file says. |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
142 if mode not in ('auto', 'terminfo'): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
143 return |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
144 ui._terminfoparams.update(_baseterminfoparams) |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
145 |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
146 for key, val in ui.configitems('color'): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
147 if key.startswith('color.'): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
148 newval = (False, int(val), '') |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
149 ui._terminfoparams[key[6:]] = newval |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
150 elif key.startswith('terminfo.'): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
151 newval = (True, '', val.replace('\\E', '\x1b')) |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
152 ui._terminfoparams[key[9:]] = newval |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
153 try: |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
154 curses.setupterm() |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
155 except curses.error as e: |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
156 ui._terminfoparams.clear() |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
157 return |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
158 |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
159 for key, (b, e, c) in ui._terminfoparams.items(): |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
160 if not b: |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
161 continue |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
162 if not c and not curses.tigetstr(e): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
163 # Most terminals don't support dim, invis, etc, so don't be |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
164 # noisy and use ui.debug(). |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
165 ui.debug("no terminfo entry for %s\n" % e) |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
166 del ui._terminfoparams[key] |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
167 if not curses.tigetstr('setaf') or not curses.tigetstr('setab'): |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
168 # Only warn about missing terminfo entries if we explicitly asked for |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
169 # terminfo mode. |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
170 if mode == "terminfo": |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
171 ui.warn(_("no terminfo entry for setab/setaf: reverting to " |
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
172 "ECMA-48 color\n")) |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
173 ui._terminfoparams.clear() |
31100
8903f67b9ca8
color: move 'terminfosetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31089
diff
changeset
|
174 |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
175 def setup(ui): |
31105
45be7590301d
color: move triggering of the initialisation logic in core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31103
diff
changeset
|
176 """configure color on a ui |
45be7590301d
color: move triggering of the initialisation logic in core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31103
diff
changeset
|
177 |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
178 That function both set the colormode for the ui object and read |
31105
45be7590301d
color: move triggering of the initialisation logic in core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31103
diff
changeset
|
179 the configuration looking for custom colors and effect definitions.""" |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
180 mode = _modesetup(ui) |
31106
a185b903bda3
color: have the 'ui' object carry the '_colormode' directly
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31105
diff
changeset
|
181 ui._colormode = mode |
31105
45be7590301d
color: move triggering of the initialisation logic in core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31103
diff
changeset
|
182 if mode and mode != 'debug': |
45be7590301d
color: move triggering of the initialisation logic in core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31103
diff
changeset
|
183 configstyles(ui) |
45be7590301d
color: move triggering of the initialisation logic in core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31103
diff
changeset
|
184 |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
185 def _modesetup(ui): |
31103
c1997c5d1ae3
color: handle 'ui.plain()' directly in mode setup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31101
diff
changeset
|
186 if ui.plain(): |
c1997c5d1ae3
color: handle 'ui.plain()' directly in mode setup
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31101
diff
changeset
|
187 return None |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
188 default = 'never' |
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
189 if _enabledbydefault: |
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
190 default = 'auto' |
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
191 config = ui.config('ui', 'color', default) |
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
192 if config == 'debug': |
31101
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
193 return 'debug' |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
194 |
31110
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
195 auto = (config == 'auto') |
7fec37746417
color: add a 'ui.color' option to control color behavior
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31109
diff
changeset
|
196 always = not auto and util.parsebool(config) |
31101
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
197 if not always and not auto: |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
198 return None |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
199 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
200 formatted = (always or (encoding.environ.get('TERM') != 'dumb' |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
201 and ui.formatted())) |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
202 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
203 mode = ui.config('color', 'mode', 'auto') |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
204 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
205 # If pager is active, color.pagermode overrides color.mode. |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
206 if getattr(ui, 'pageractive', False): |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
207 mode = ui.config('color', 'pagermode', mode) |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
208 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
209 realmode = mode |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
210 if mode == 'auto': |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
211 if pycompat.osname == 'nt': |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
212 term = encoding.environ.get('TERM') |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
213 # TERM won't be defined in a vanilla cmd.exe environment. |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
214 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
215 # UNIX-like environments on Windows such as Cygwin and MSYS will |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
216 # set TERM. They appear to make a best effort attempt at setting it |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
217 # to something appropriate. However, not all environments with TERM |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
218 # defined support ANSI. Since "ansi" could result in terminal |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
219 # gibberish, we error on the side of selecting "win32". However, if |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
220 # w32effects is not defined, we almost certainly don't support |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
221 # "win32", so don't even try. |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
222 if (term and 'xterm' in term) or not w32effects: |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
223 realmode = 'ansi' |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
224 else: |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
225 realmode = 'win32' |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
226 else: |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
227 realmode = 'ansi' |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
228 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
229 def modewarn(): |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
230 # only warn if color.mode was explicitly set and we're in |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
231 # a formatted terminal |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
232 if mode == realmode and ui.formatted(): |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
233 ui.warn(_('warning: failed to set color mode to %s\n') % mode) |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
234 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
235 if realmode == 'win32': |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
236 ui._terminfoparams.clear() |
31101
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
237 if not w32effects: |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
238 modewarn() |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
239 return None |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
240 elif realmode == 'ansi': |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
241 ui._terminfoparams.clear() |
31101
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
242 elif realmode == 'terminfo': |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
243 _terminfosetup(ui, mode) |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
244 if not ui._terminfoparams: |
31101
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
245 ## FIXME Shouldn't we return None in this case too? |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
246 modewarn() |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
247 realmode = 'ansi' |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
248 else: |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
249 return None |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
250 |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
251 if always or (auto and formatted): |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
252 return realmode |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
253 return None |
9021a94a7dbf
color: move 'modesetup' into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31100
diff
changeset
|
254 |
30971
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
255 def configstyles(ui): |
31116
6483e49204ee
color: rename '_styles' to '_defaultstyles' for clarity
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31115
diff
changeset
|
256 ui._styles.update(_defaultstyles) |
30971
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
257 for status, cfgeffects in ui.configitems('color'): |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
258 if '.' not in status or status.startswith(('color.', 'terminfo.')): |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
259 continue |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
260 cfgeffects = ui.configlist('color', status) |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
261 if cfgeffects: |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
262 good = [] |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
263 for e in cfgeffects: |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
264 if valideffect(ui, e): |
30971
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
265 good.append(e) |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
266 else: |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
267 ui.warn(_("ignoring unknown color/effect %r " |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
268 "(configured in color.%s)\n") |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
269 % (e, status)) |
31115
f5131d4f512a
color: move 'styles' definition on the 'ui' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31114
diff
changeset
|
270 ui._styles[status] = ' '.join(good) |
30971
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30970
diff
changeset
|
271 |
31689
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
272 def _activeeffects(ui): |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
273 '''Return the effects map for the color mode set on the ui.''' |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
274 if ui._colormode == 'win32': |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
275 return w32effects |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
276 elif ui._colormode is not None: |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
277 return _effects |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
278 return {} |
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
279 |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
280 def valideffect(ui, effect): |
30969
ddc80d1777a6
color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30968
diff
changeset
|
281 'Determine if the effect is valid or not.' |
31689
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
282 return ((not ui._terminfoparams and effect in _activeeffects(ui)) |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
283 or (effect in ui._terminfoparams |
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
284 or effect[:-11] in ui._terminfoparams)) |
30972
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
285 |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
286 def _effect_str(ui, effect): |
30972
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
287 '''Helper function for render_effects().''' |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
288 |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
289 bg = False |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
290 if effect.endswith('_background'): |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
291 bg = True |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
292 effect = effect[:-11] |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
293 try: |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
294 attr, val, termcode = ui._terminfoparams[effect] |
30972
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
295 except KeyError: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
296 return '' |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
297 if attr: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
298 if termcode: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
299 return termcode |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
300 else: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
301 return curses.tigetstr(val) |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
302 elif bg: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
303 return curses.tparm(curses.tigetstr('setab'), val) |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
304 else: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30971
diff
changeset
|
305 return curses.tparm(curses.tigetstr('setaf'), val) |
30973
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30972
diff
changeset
|
306 |
31518
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
307 def _mergeeffects(text, start, stop): |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
308 """Insert start sequence at every occurrence of stop sequence |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
309 |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
310 >>> s = _mergeeffects('cyan', '[C]', '|') |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
311 >>> s = _mergeeffects(s + 'yellow', '[Y]', '|') |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
312 >>> s = _mergeeffects('ma' + s + 'genta', '[M]', '|') |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
313 >>> s = _mergeeffects('red' + s, '[R]', '|') |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
314 >>> s |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
315 '[R]red[M]ma[Y][C]cyan|[R][M][Y]yellow|[R][M]genta|' |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
316 """ |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
317 parts = [] |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
318 for t in text.split(stop): |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
319 if not t: |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
320 continue |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
321 parts.extend([start, t, stop]) |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
322 return ''.join(parts) |
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
323 |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
324 def _render_effects(ui, text, effects): |
30973
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30972
diff
changeset
|
325 'Wrap text in commands to turn on each effect.' |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30972
diff
changeset
|
326 if not text: |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30972
diff
changeset
|
327 return text |
31113
268caf97c38f
color: move the dict with terminfo parameters on the ui object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31112
diff
changeset
|
328 if ui._terminfoparams: |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
329 start = ''.join(_effect_str(ui, effect) |
31071
350d737e059d
color: minor reversal of two conditional clause for clarity
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31067
diff
changeset
|
330 for effect in ['none'] + effects.split()) |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
331 stop = _effect_str(ui, 'none') |
31071
350d737e059d
color: minor reversal of two conditional clause for clarity
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31067
diff
changeset
|
332 else: |
31689
57a22f699179
color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents:
31521
diff
changeset
|
333 activeeffects = _activeeffects(ui) |
31716
439a387ca6f1
color: replace str() with pycompat.bytestr()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31689
diff
changeset
|
334 start = [pycompat.bytestr(activeeffects[e]) |
439a387ca6f1
color: replace str() with pycompat.bytestr()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31689
diff
changeset
|
335 for e in ['none'] + effects.split()] |
30973
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30972
diff
changeset
|
336 start = '\033[' + ';'.join(start) + 'm' |
31716
439a387ca6f1
color: replace str() with pycompat.bytestr()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31689
diff
changeset
|
337 stop = '\033[' + pycompat.bytestr(activeeffects['none']) + 'm' |
31518
43d6ef658874
color: insert color code after every "\e[0m" (issue5413)
Yuya Nishihara <yuya@tcha.org>
parents:
31499
diff
changeset
|
338 return _mergeeffects(text, start, stop) |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
339 |
31521
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
340 _ansieffectre = re.compile(br'\x1b\[[0-9;]*m') |
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
341 |
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
342 def stripeffects(text): |
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
343 """Strip ANSI control codes which could be inserted by colorlabel()""" |
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
344 return _ansieffectre.sub('', text) |
44c591f63458
templater: make pad() strip color codes before computing width (issue5416)
Yuya Nishihara <yuya@tcha.org>
parents:
31518
diff
changeset
|
345 |
31086
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
346 def colorlabel(ui, msg, label): |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
347 """add color control code according to the mode""" |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
348 if ui._colormode == 'debug': |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
349 if label and msg: |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
350 if msg[-1] == '\n': |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
351 msg = "[%s|%s]\n" % (label, msg[:-1]) |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
352 else: |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
353 msg = "[%s|%s]" % (label, msg) |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
354 elif ui._colormode is not None: |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
355 effects = [] |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
356 for l in label.split(): |
31115
f5131d4f512a
color: move 'styles' definition on the 'ui' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31114
diff
changeset
|
357 s = ui._styles.get(l, '') |
31086
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
358 if s: |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
359 effects.append(s) |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
360 elif valideffect(ui, l): |
31086
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
361 effects.append(l) |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
362 effects = ' '.join(effects) |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
363 if effects: |
31112
7f056fdbe37e
color: add ui to effect rendering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31110
diff
changeset
|
364 msg = '\n'.join([_render_effects(ui, line, effects) |
31086
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
365 for line in msg.split('\n')]) |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
366 return msg |
e6082078c853
color: move the 'colorlabel' function in the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31071
diff
changeset
|
367 |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
368 w32effects = None |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
369 if pycompat.osname == 'nt': |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
370 import ctypes |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
371 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
372 _kernel32 = ctypes.windll.kernel32 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
373 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
374 _WORD = ctypes.c_ushort |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
375 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
376 _INVALID_HANDLE_VALUE = -1 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
377 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
378 class _COORD(ctypes.Structure): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
379 _fields_ = [('X', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
380 ('Y', ctypes.c_short)] |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
381 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
382 class _SMALL_RECT(ctypes.Structure): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
383 _fields_ = [('Left', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
384 ('Top', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
385 ('Right', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
386 ('Bottom', ctypes.c_short)] |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
387 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
388 class _CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
389 _fields_ = [('dwSize', _COORD), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
390 ('dwCursorPosition', _COORD), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
391 ('wAttributes', _WORD), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
392 ('srWindow', _SMALL_RECT), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
393 ('dwMaximumWindowSize', _COORD)] |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
394 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
395 _STD_OUTPUT_HANDLE = 0xfffffff5 # (DWORD)-11 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
396 _STD_ERROR_HANDLE = 0xfffffff4 # (DWORD)-12 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
397 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
398 _FOREGROUND_BLUE = 0x0001 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
399 _FOREGROUND_GREEN = 0x0002 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
400 _FOREGROUND_RED = 0x0004 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
401 _FOREGROUND_INTENSITY = 0x0008 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
402 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
403 _BACKGROUND_BLUE = 0x0010 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
404 _BACKGROUND_GREEN = 0x0020 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
405 _BACKGROUND_RED = 0x0040 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
406 _BACKGROUND_INTENSITY = 0x0080 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
407 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
408 _COMMON_LVB_REVERSE_VIDEO = 0x4000 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
409 _COMMON_LVB_UNDERSCORE = 0x8000 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
410 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
411 # http://msdn.microsoft.com/en-us/library/ms682088%28VS.85%29.aspx |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
412 w32effects = { |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
413 'none': -1, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
414 'black': 0, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
415 'red': _FOREGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
416 'green': _FOREGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
417 'yellow': _FOREGROUND_RED | _FOREGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
418 'blue': _FOREGROUND_BLUE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
419 'magenta': _FOREGROUND_BLUE | _FOREGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
420 'cyan': _FOREGROUND_BLUE | _FOREGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
421 'white': _FOREGROUND_RED | _FOREGROUND_GREEN | _FOREGROUND_BLUE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
422 'bold': _FOREGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
423 'black_background': 0x100, # unused value > 0x0f |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
424 'red_background': _BACKGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
425 'green_background': _BACKGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
426 'yellow_background': _BACKGROUND_RED | _BACKGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
427 'blue_background': _BACKGROUND_BLUE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
428 'purple_background': _BACKGROUND_BLUE | _BACKGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
429 'cyan_background': _BACKGROUND_BLUE | _BACKGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
430 'white_background': (_BACKGROUND_RED | _BACKGROUND_GREEN | |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
431 _BACKGROUND_BLUE), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
432 'bold_background': _BACKGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
433 'underline': _COMMON_LVB_UNDERSCORE, # double-byte charsets only |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
434 'inverse': _COMMON_LVB_REVERSE_VIDEO, # double-byte charsets only |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
435 } |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
436 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
437 passthrough = set([_FOREGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
438 _BACKGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
439 _COMMON_LVB_UNDERSCORE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
440 _COMMON_LVB_REVERSE_VIDEO]) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
441 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
442 stdout = _kernel32.GetStdHandle( |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
443 _STD_OUTPUT_HANDLE) # don't close the handle returned |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
444 if stdout is None or stdout == _INVALID_HANDLE_VALUE: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
445 w32effects = None |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
446 else: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
447 csbi = _CONSOLE_SCREEN_BUFFER_INFO() |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
448 if not _kernel32.GetConsoleScreenBufferInfo( |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
449 stdout, ctypes.byref(csbi)): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
450 # stdout may not support GetConsoleScreenBufferInfo() |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
451 # when called from subprocess or redirected |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
452 w32effects = None |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
453 else: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
454 origattr = csbi.wAttributes |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
455 ansire = re.compile('\033\[([^m]*)m([^\033]*)(.*)', |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
456 re.MULTILINE | re.DOTALL) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
457 |
31114
1613c55ad3d6
color: pass 'ui' to 'win32print'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31113
diff
changeset
|
458 def win32print(ui, writefunc, *msgs, **opts): |
31089
a2ee25ff75e5
color: add multiple messages input support to 'win32print'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31088
diff
changeset
|
459 for text in msgs: |
31114
1613c55ad3d6
color: pass 'ui' to 'win32print'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31113
diff
changeset
|
460 _win32print(ui, text, writefunc, **opts) |
31089
a2ee25ff75e5
color: add multiple messages input support to 'win32print'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31088
diff
changeset
|
461 |
31114
1613c55ad3d6
color: pass 'ui' to 'win32print'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31113
diff
changeset
|
462 def _win32print(ui, text, writefunc, **opts): |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
463 label = opts.get('label', '') |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
464 attr = origattr |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
465 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
466 def mapcolor(val, attr): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
467 if val == -1: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
468 return origattr |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
469 elif val in passthrough: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
470 return attr | val |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
471 elif val > 0x0f: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
472 return (val & 0x70) | (attr & 0x8f) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
473 else: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
474 return (val & 0x07) | (attr & 0xf8) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
475 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
476 # determine console attributes based on labels |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
477 for l in label.split(): |
31115
f5131d4f512a
color: move 'styles' definition on the 'ui' object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31114
diff
changeset
|
478 style = ui._styles.get(l, '') |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
479 for effect in style.split(): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
480 try: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
481 attr = mapcolor(w32effects[effect], attr) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
482 except KeyError: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
483 # w32effects could not have certain attributes so we skip |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
484 # them if not found |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
485 pass |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
486 # hack to ensure regexp finds data |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
487 if not text.startswith('\033['): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
488 text = '\033[m' + text |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
489 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
490 # Look for ANSI-like codes embedded in text |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
491 m = re.match(ansire, text) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
492 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
493 try: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
494 while m: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
495 for sattr in m.group(1).split(';'): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
496 if sattr: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
497 attr = mapcolor(int(sattr), attr) |
31499
31d2ddfd338c
color: sync text attributes and buffered text output on Windows (issue5508)
Matt Harbison <matt_harbison@yahoo.com>
parents:
31123
diff
changeset
|
498 ui.flush() |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
499 _kernel32.SetConsoleTextAttribute(stdout, attr) |
31088
75c4aafee490
color: clarify name of an argument of 'win32print'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31086
diff
changeset
|
500 writefunc(m.group(2), **opts) |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
501 m = re.match(ansire, m.group(3)) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
502 finally: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
503 # Explicitly reset original attributes |
31499
31d2ddfd338c
color: sync text attributes and buffered text output on Windows (issue5508)
Matt Harbison <matt_harbison@yahoo.com>
parents:
31123
diff
changeset
|
504 ui.flush() |
31067
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30973
diff
changeset
|
505 _kernel32.SetConsoleTextAttribute(stdout, origattr) |