annotate mercurial/color.py @ 30973:e5363cb96233

color: move the '_render_effects' function to the core module
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 22 Dec 2016 02:38:53 +0100
parents a3c7e42c7a1f
children a0bde5ec3a46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
30971
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
10 from .i18n import _
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
11
30968
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
12 try:
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
13 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
14 # 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
15 # 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: 30967
diff changeset
16 _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: 30967
diff changeset
17 'standout': (True, 'smso', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
18 'underline': (True, 'smul', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
19 'reverse': (True, 'rev', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
20 'inverse': (True, 'rev', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
21 'blink': (True, 'blink', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
22 'dim': (True, 'dim', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
23 'bold': (True, 'bold', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
24 'invisible': (True, 'invis', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
25 'italic': (True, 'sitm', ''),
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
26 '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: 30967
diff changeset
27 '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: 30967
diff changeset
28 '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: 30967
diff changeset
29 '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: 30967
diff changeset
30 '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: 30967
diff changeset
31 '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: 30967
diff changeset
32 '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: 30967
diff changeset
33 '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: 30967
diff changeset
34 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
35 curses = None
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
36 _terminfo_params = {}
0d2a58a04080 color: move '_terminfo_params' into the core 'color' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30967
diff changeset
37
30967
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
38 # start and stop parameters for effects
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
39 _effects = {'none': 0,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
40 'black': 30,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
41 'red': 31,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
42 'green': 32,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
43 'yellow': 33,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
44 'blue': 34,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
45 'magenta': 35,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
46 'cyan': 36,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
47 'white': 37,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
48 'bold': 1,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
49 'italic': 3,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
50 'underline': 4,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
51 'inverse': 7,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
52 'dim': 2,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
53 'black_background': 40,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
54 'red_background': 41,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
55 'green_background': 42,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
56 'yellow_background': 43,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
57 'blue_background': 44,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
58 'purple_background': 45,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
59 'cyan_background': 46,
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
60 'white_background': 47}
20990991d384 color: move '_effect' mapping into core
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30653
diff changeset
61
30652
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
62 _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
63 '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
64 '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
65 '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
66 '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
67 '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
68 '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
69 '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
70 '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
71 '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
72 '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
73 '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
74 '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
75 '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
76 '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
77 '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
78 '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
79 '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
80 '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
81 '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
82 '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
83 'diff.tab': '',
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
84 '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
85 'changeset.public' : '',
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
86 'changeset.draft' : '',
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
87 'changeset.secret' : '',
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
88 '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
89 '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
90 '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
91 '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
92 '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
93 'patchbomb.finalsummary': '',
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
94 '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
95 '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
96 '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
97 'patchbomb.diffstats': '',
1ec42bdd7874 color: move hgext.color._styles to mercurial.color.style
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
98 '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
99 '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
100 '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
101 '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
102 '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
103 '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
104 '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
105 '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
106 '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
107 '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
108 '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
109 '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
110 '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
111 '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
112 '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
113 '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
114 'tags.local': 'black bold'}
30653
b2be4ccaff1d color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30652
diff changeset
115
b2be4ccaff1d color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30652
diff changeset
116 def loadcolortable(ui, extname, colortable):
b2be4ccaff1d color: load 'colortable' from extension using an 'extraloader'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30652
diff changeset
117 _styles.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
118
30971
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
119 def configstyles(ui):
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
120 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
121 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
122 continue
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
123 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
124 if cfgeffects:
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
125 good = []
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
126 for e in cfgeffects:
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
127 if valideffect(e):
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
128 good.append(e)
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
129 else:
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
130 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
131 "(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
132 % (e, status))
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
133 _styles[status] = ' '.join(good)
bb6385882cfa color: move configstyles into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30970
diff changeset
134
30969
ddc80d1777a6 color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30968
diff changeset
135 def valideffect(effect):
ddc80d1777a6 color: move 'valideffect' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30968
diff changeset
136 'Determine if the effect is valid or not.'
30970
683606a829e8 color: rework conditional 'valideffect'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30969
diff changeset
137 return ((not _terminfo_params and effect in _effects)
683606a829e8 color: rework conditional 'valideffect'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30969
diff changeset
138 or (effect in _terminfo_params
683606a829e8 color: rework conditional 'valideffect'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30969
diff changeset
139 or effect[:-11] in _terminfo_params))
30972
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
140
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
141 def _effect_str(effect):
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
142 '''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
143
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
144 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
145 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
146 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
147 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
148 try:
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
149 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: 30971
diff changeset
150 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
151 return ''
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
152 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
153 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
154 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
155 else:
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
156 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
157 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
158 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
159 else:
a3c7e42c7a1f color: move '_effect_str' function into the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30971
diff changeset
160 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
161
e5363cb96233 color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30972
diff changeset
162 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: 30972
diff changeset
163 '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
164 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
165 return 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
166 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: 30972
diff changeset
167 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: 30972
diff changeset
168 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: 30972
diff changeset
169 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: 30972
diff changeset
170 else:
e5363cb96233 color: move the '_render_effects' function to the core module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30972
diff changeset
171 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: 30972
diff changeset
172 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: 30972
diff changeset
173 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: 30972
diff changeset
174 return ''.join([start, text, stop])