Mercurial > hg-stable
annotate mercurial/color.py @ 31084:a0bde5ec3a46
color: move 'win32' declaration to the core module
This is another part of moving color implementation into core. before we can
move the advance logic, we need to move the basic definition and building
bricks. This is one more step on that road.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 22 Dec 2016 03:11:19 +0100 |
parents | e5363cb96233 |
children | 350d737e059d |
rev | line source |
---|---|
30656
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 |
30991
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
10 from .i18n import _ |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
11 |
31084
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
12 from . import pycompat |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
13 |
30988
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
14 try: |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
15 import curses |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
16 # 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:
30987
diff
changeset
|
17 # color number. This will also force-load the curses module. |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
18 _terminfo_params = {'none': (True, 'sgr0', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
19 'standout': (True, 'smso', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
20 'underline': (True, 'smul', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
21 'reverse': (True, 'rev', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
22 'inverse': (True, 'rev', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
23 'blink': (True, 'blink', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
24 'dim': (True, 'dim', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
25 'bold': (True, 'bold', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
26 'invisible': (True, 'invis', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
27 'italic': (True, 'sitm', ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
28 'black': (False, curses.COLOR_BLACK, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
29 'red': (False, curses.COLOR_RED, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
30 'green': (False, curses.COLOR_GREEN, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
31 'yellow': (False, curses.COLOR_YELLOW, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
32 'blue': (False, curses.COLOR_BLUE, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
33 'magenta': (False, curses.COLOR_MAGENTA, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
34 'cyan': (False, curses.COLOR_CYAN, ''), |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
35 'white': (False, curses.COLOR_WHITE, '')} |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
36 except ImportError: |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
37 curses = None |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
38 _terminfo_params = {} |
0d2a58a04080
color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30987
diff
changeset
|
39 |
30987
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
40 # start and stop parameters for effects |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
41 _effects = {'none': 0, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
42 'black': 30, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
43 'red': 31, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
44 'green': 32, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
45 'yellow': 33, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
46 'blue': 34, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
47 'magenta': 35, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
48 'cyan': 36, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
49 'white': 37, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
50 'bold': 1, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
51 'italic': 3, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
52 'underline': 4, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
53 'inverse': 7, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
54 'dim': 2, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
55 'black_background': 40, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
56 'red_background': 41, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
57 'green_background': 42, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
58 'yellow_background': 43, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
59 'blue_background': 44, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
60 'purple_background': 45, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
61 'cyan_background': 46, |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
62 'white_background': 47} |
20990991d384
color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30657
diff
changeset
|
63 |
30656
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
64 _styles = {'grep.match': 'red bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
65 'grep.linenumber': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
66 'grep.rev': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
67 'grep.change': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
68 'grep.sep': 'cyan', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
69 'grep.filename': 'magenta', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
70 'grep.user': 'magenta', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
71 'grep.date': 'magenta', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
72 'bookmarks.active': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
73 'branches.active': 'none', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
74 'branches.closed': 'black bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
75 'branches.current': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
76 'branches.inactive': 'none', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
77 'diff.changed': 'white', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
78 'diff.deleted': 'red', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
79 'diff.diffline': 'bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
80 'diff.extended': 'cyan bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
81 'diff.file_a': 'red bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
82 'diff.file_b': 'green bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
83 'diff.hunk': 'magenta', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
84 'diff.inserted': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
85 'diff.tab': '', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
86 'diff.trailingwhitespace': 'bold red_background', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
87 'changeset.public' : '', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
88 'changeset.draft' : '', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
89 'changeset.secret' : '', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
90 'diffstat.deleted': 'red', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
91 'diffstat.inserted': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
92 'histedit.remaining': 'red bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
93 'ui.prompt': 'yellow', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
94 'log.changeset': 'yellow', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
95 'patchbomb.finalsummary': '', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
96 'patchbomb.from': 'magenta', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
97 'patchbomb.to': 'cyan', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
98 'patchbomb.subject': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
99 'patchbomb.diffstats': '', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
100 'rebase.rebased': 'blue', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
101 'rebase.remaining': 'red bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
102 'resolve.resolved': 'green bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
103 'resolve.unresolved': 'red bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
104 'shelve.age': 'cyan', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
105 'shelve.newest': 'green bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
106 'shelve.name': 'blue bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
107 'status.added': 'green bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
108 'status.clean': 'none', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
109 'status.copied': 'none', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
110 'status.deleted': 'cyan bold underline', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
111 'status.ignored': 'black bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
112 'status.modified': 'blue bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
113 'status.removed': 'red bold', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
114 'status.unknown': 'magenta bold underline', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
115 'tags.normal': 'green', |
1ec42bdd7874
color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
116 'tags.local': 'black bold'} |
30657
b2be4ccaff1d
color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30656
diff
changeset
|
117 |
b2be4ccaff1d
color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30656
diff
changeset
|
118 def loadcolortable(ui, extname, colortable): |
b2be4ccaff1d
color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30656
diff
changeset
|
119 _styles.update(colortable) |
30989
ddc80d1777a6
color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30988
diff
changeset
|
120 |
30991
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
121 def configstyles(ui): |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
122 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:
30990
diff
changeset
|
123 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:
30990
diff
changeset
|
124 continue |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
125 cfgeffects = ui.configlist('color', status) |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
126 if cfgeffects: |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
127 good = [] |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
128 for e in cfgeffects: |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
129 if valideffect(e): |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
130 good.append(e) |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
131 else: |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
132 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:
30990
diff
changeset
|
133 "(configured in color.%s)\n") |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
134 % (e, status)) |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
135 _styles[status] = ' '.join(good) |
bb6385882cfa
color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30990
diff
changeset
|
136 |
30989
ddc80d1777a6
color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30988
diff
changeset
|
137 def valideffect(effect): |
ddc80d1777a6
color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30988
diff
changeset
|
138 'Determine if the effect is valid or not.' |
30990
683606a829e8
color: rework conditional 'valideffect'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30989
diff
changeset
|
139 return ((not _terminfo_params and effect in _effects) |
683606a829e8
color: rework conditional 'valideffect'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30989
diff
changeset
|
140 or (effect in _terminfo_params |
683606a829e8
color: rework conditional 'valideffect'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30989
diff
changeset
|
141 or effect[:-11] in _terminfo_params)) |
30992
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
142 |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
143 def _effect_str(effect): |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
144 '''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:
30991
diff
changeset
|
145 |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
146 bg = False |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
147 if effect.endswith('_background'): |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
148 bg = True |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
149 effect = effect[:-11] |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
150 try: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
151 attr, val, termcode = _terminfo_params[effect] |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
152 except KeyError: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
153 return '' |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
154 if attr: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
155 if termcode: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
156 return termcode |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
157 else: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
158 return curses.tigetstr(val) |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
159 elif bg: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
160 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:
30991
diff
changeset
|
161 else: |
a3c7e42c7a1f
color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30991
diff
changeset
|
162 return curses.tparm(curses.tigetstr('setaf'), val) |
30993
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
163 |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
164 def _render_effects(text, effects): |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
165 '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:
30992
diff
changeset
|
166 if not text: |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
167 return text |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
168 if not _terminfo_params: |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
169 start = [str(_effects[e]) for e in ['none'] + effects.split()] |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
170 start = '\033[' + ';'.join(start) + 'm' |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
171 stop = '\033[' + str(_effects['none']) + 'm' |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
172 else: |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
173 start = ''.join(_effect_str(effect) |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
174 for effect in ['none'] + effects.split()) |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
175 stop = _effect_str('none') |
e5363cb96233
color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30992
diff
changeset
|
176 return ''.join([start, text, stop]) |
31084
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
177 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
178 w32effects = None |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
179 if pycompat.osname == 'nt': |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
180 import ctypes |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
181 import re |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
182 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
183 _kernel32 = ctypes.windll.kernel32 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
184 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
185 _WORD = ctypes.c_ushort |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
186 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
187 _INVALID_HANDLE_VALUE = -1 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
188 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
189 class _COORD(ctypes.Structure): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
190 _fields_ = [('X', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
191 ('Y', ctypes.c_short)] |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
192 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
193 class _SMALL_RECT(ctypes.Structure): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
194 _fields_ = [('Left', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
195 ('Top', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
196 ('Right', ctypes.c_short), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
197 ('Bottom', ctypes.c_short)] |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
198 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
199 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:
30993
diff
changeset
|
200 _fields_ = [('dwSize', _COORD), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
201 ('dwCursorPosition', _COORD), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
202 ('wAttributes', _WORD), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
203 ('srWindow', _SMALL_RECT), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
204 ('dwMaximumWindowSize', _COORD)] |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
205 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
206 _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:
30993
diff
changeset
|
207 _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:
30993
diff
changeset
|
208 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
209 _FOREGROUND_BLUE = 0x0001 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
210 _FOREGROUND_GREEN = 0x0002 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
211 _FOREGROUND_RED = 0x0004 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
212 _FOREGROUND_INTENSITY = 0x0008 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
213 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
214 _BACKGROUND_BLUE = 0x0010 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
215 _BACKGROUND_GREEN = 0x0020 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
216 _BACKGROUND_RED = 0x0040 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
217 _BACKGROUND_INTENSITY = 0x0080 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
218 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
219 _COMMON_LVB_REVERSE_VIDEO = 0x4000 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
220 _COMMON_LVB_UNDERSCORE = 0x8000 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
221 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
222 # 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:
30993
diff
changeset
|
223 w32effects = { |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
224 'none': -1, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
225 'black': 0, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
226 'red': _FOREGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
227 'green': _FOREGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
228 'yellow': _FOREGROUND_RED | _FOREGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
229 'blue': _FOREGROUND_BLUE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
230 'magenta': _FOREGROUND_BLUE | _FOREGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
231 'cyan': _FOREGROUND_BLUE | _FOREGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
232 '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:
30993
diff
changeset
|
233 'bold': _FOREGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
234 '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:
30993
diff
changeset
|
235 'red_background': _BACKGROUND_RED, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
236 'green_background': _BACKGROUND_GREEN, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
237 '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:
30993
diff
changeset
|
238 'blue_background': _BACKGROUND_BLUE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
239 '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:
30993
diff
changeset
|
240 '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:
30993
diff
changeset
|
241 '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:
30993
diff
changeset
|
242 _BACKGROUND_BLUE), |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
243 'bold_background': _BACKGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
244 '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:
30993
diff
changeset
|
245 '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:
30993
diff
changeset
|
246 } |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
247 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
248 passthrough = set([_FOREGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
249 _BACKGROUND_INTENSITY, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
250 _COMMON_LVB_UNDERSCORE, |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
251 _COMMON_LVB_REVERSE_VIDEO]) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
252 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
253 stdout = _kernel32.GetStdHandle( |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
254 _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:
30993
diff
changeset
|
255 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:
30993
diff
changeset
|
256 w32effects = None |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
257 else: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
258 csbi = _CONSOLE_SCREEN_BUFFER_INFO() |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
259 if not _kernel32.GetConsoleScreenBufferInfo( |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
260 stdout, ctypes.byref(csbi)): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
261 # stdout may not support GetConsoleScreenBufferInfo() |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
262 # 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:
30993
diff
changeset
|
263 w32effects = None |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
264 else: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
265 origattr = csbi.wAttributes |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
266 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:
30993
diff
changeset
|
267 re.MULTILINE | re.DOTALL) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
268 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
269 def win32print(text, orig, **opts): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
270 label = opts.get('label', '') |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
271 attr = origattr |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
272 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
273 def mapcolor(val, attr): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
274 if val == -1: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
275 return origattr |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
276 elif val in passthrough: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
277 return attr | val |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
278 elif val > 0x0f: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
279 return (val & 0x70) | (attr & 0x8f) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
280 else: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
281 return (val & 0x07) | (attr & 0xf8) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
282 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
283 # 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:
30993
diff
changeset
|
284 for l in label.split(): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
285 style = _styles.get(l, '') |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
286 for effect in style.split(): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
287 try: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
288 attr = mapcolor(w32effects[effect], attr) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
289 except KeyError: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
290 # 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:
30993
diff
changeset
|
291 # them if not found |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
292 pass |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
293 # 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:
30993
diff
changeset
|
294 if not text.startswith('\033['): |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
295 text = '\033[m' + text |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
296 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
297 # 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:
30993
diff
changeset
|
298 m = re.match(ansire, text) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
299 |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
300 try: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
301 while m: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
302 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:
30993
diff
changeset
|
303 if sattr: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
304 attr = mapcolor(int(sattr), attr) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
305 _kernel32.SetConsoleTextAttribute(stdout, attr) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
306 orig(m.group(2), **opts) |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
307 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:
30993
diff
changeset
|
308 finally: |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
309 # Explicitly reset original attributes |
a0bde5ec3a46
color: move 'win32' declaration to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30993
diff
changeset
|
310 _kernel32.SetConsoleTextAttribute(stdout, origattr) |