Show More
@@ -212,7 +212,7 b' def _debugdisplaycolor(ui):' | |||
|
212 | 212 | color._styles.clear() |
|
213 | 213 | for effect in color._effects.keys(): |
|
214 | 214 | color._styles[effect] = effect |
|
215 |
if |
|
|
215 | if ui._terminfoparams: | |
|
216 | 216 | for k, v in ui.configitems('color'): |
|
217 | 217 | if k.startswith('color.'): |
|
218 | 218 | color._styles[k] = k[6:] |
@@ -19,7 +19,7 b' try:' | |||
|
19 | 19 | import curses |
|
20 | 20 | # Mapping from effect name to terminfo attribute name (or raw code) or |
|
21 | 21 | # color number. This will also force-load the curses module. |
|
22 |
_terminfo |
|
|
22 | _baseterminfoparams = { | |
|
23 | 23 | 'none': (True, 'sgr0', ''), |
|
24 | 24 | 'standout': (True, 'smso', ''), |
|
25 | 25 | 'underline': (True, 'smul', ''), |
@@ -41,7 +41,7 b' try:' | |||
|
41 | 41 | } |
|
42 | 42 | except ImportError: |
|
43 | 43 | curses = None |
|
44 |
_terminfo |
|
|
44 | _baseterminfoparams = {} | |
|
45 | 45 | |
|
46 | 46 | # allow the extensions to change the default |
|
47 | 47 | _enabledbydefault = False |
@@ -140,35 +140,36 b' def _terminfosetup(ui, mode):' | |||
|
140 | 140 | # Otherwise, see what the config file says. |
|
141 | 141 | if mode not in ('auto', 'terminfo'): |
|
142 | 142 | return |
|
143 | ui._terminfoparams.update(_baseterminfoparams) | |
|
143 | 144 | |
|
144 | 145 | for key, val in ui.configitems('color'): |
|
145 | 146 | if key.startswith('color.'): |
|
146 | 147 | newval = (False, int(val), '') |
|
147 |
_terminfo |
|
|
148 | ui._terminfoparams[key[6:]] = newval | |
|
148 | 149 | elif key.startswith('terminfo.'): |
|
149 | 150 | newval = (True, '', val.replace('\\E', '\x1b')) |
|
150 |
_terminfo |
|
|
151 | ui._terminfoparams[key[9:]] = newval | |
|
151 | 152 | try: |
|
152 | 153 | curses.setupterm() |
|
153 | 154 | except curses.error as e: |
|
154 |
_terminfo |
|
|
155 | ui._terminfoparams.clear() | |
|
155 | 156 | return |
|
156 | 157 | |
|
157 |
for key, (b, e, c) in _terminfo |
|
|
158 | for key, (b, e, c) in ui._terminfoparams.items(): | |
|
158 | 159 | if not b: |
|
159 | 160 | continue |
|
160 | 161 | if not c and not curses.tigetstr(e): |
|
161 | 162 | # Most terminals don't support dim, invis, etc, so don't be |
|
162 | 163 | # noisy and use ui.debug(). |
|
163 | 164 | ui.debug("no terminfo entry for %s\n" % e) |
|
164 |
del _terminfo |
|
|
165 | del ui._terminfoparams[key] | |
|
165 | 166 | if not curses.tigetstr('setaf') or not curses.tigetstr('setab'): |
|
166 | 167 | # Only warn about missing terminfo entries if we explicitly asked for |
|
167 | 168 | # terminfo mode. |
|
168 | 169 | if mode == "terminfo": |
|
169 | 170 | ui.warn(_("no terminfo entry for setab/setaf: reverting to " |
|
170 | 171 | "ECMA-48 color\n")) |
|
171 |
_terminfo |
|
|
172 | ui._terminfoparams.clear() | |
|
172 | 173 | |
|
173 | 174 | def setup(ui): |
|
174 | 175 | """configure color on a ui |
@@ -232,16 +233,16 b' def _modesetup(ui):' | |||
|
232 | 233 | ui.warn(_('warning: failed to set color mode to %s\n') % mode) |
|
233 | 234 | |
|
234 | 235 | if realmode == 'win32': |
|
235 |
_terminfo |
|
|
236 | ui._terminfoparams.clear() | |
|
236 | 237 | if not w32effects: |
|
237 | 238 | modewarn() |
|
238 | 239 | return None |
|
239 | 240 | _effects.update(w32effects) |
|
240 | 241 | elif realmode == 'ansi': |
|
241 |
_terminfo |
|
|
242 | ui._terminfoparams.clear() | |
|
242 | 243 | elif realmode == 'terminfo': |
|
243 | 244 | _terminfosetup(ui, mode) |
|
244 |
if not _terminfo |
|
|
245 | if not ui._terminfoparams: | |
|
245 | 246 | ## FIXME Shouldn't we return None in this case too? |
|
246 | 247 | modewarn() |
|
247 | 248 | realmode = 'ansi' |
@@ -270,9 +271,9 b' def configstyles(ui):' | |||
|
270 | 271 | |
|
271 | 272 | def valideffect(ui, effect): |
|
272 | 273 | 'Determine if the effect is valid or not.' |
|
273 |
return ((not _terminfo |
|
|
274 |
or (effect in _terminfo |
|
|
275 |
or effect[:-11] in _terminfo |
|
|
274 | return ((not ui._terminfoparams and effect in _effects) | |
|
275 | or (effect in ui._terminfoparams | |
|
276 | or effect[:-11] in ui._terminfoparams)) | |
|
276 | 277 | |
|
277 | 278 | def _effect_str(ui, effect): |
|
278 | 279 | '''Helper function for render_effects().''' |
@@ -282,7 +283,7 b' def _effect_str(ui, effect):' | |||
|
282 | 283 | bg = True |
|
283 | 284 | effect = effect[:-11] |
|
284 | 285 | try: |
|
285 |
attr, val, termcode = _terminfo |
|
|
286 | attr, val, termcode = ui._terminfoparams[effect] | |
|
286 | 287 | except KeyError: |
|
287 | 288 | return '' |
|
288 | 289 | if attr: |
@@ -299,7 +300,7 b' def _render_effects(ui, text, effects):' | |||
|
299 | 300 | 'Wrap text in commands to turn on each effect.' |
|
300 | 301 | if not text: |
|
301 | 302 | return text |
|
302 |
if _terminfo |
|
|
303 | if ui._terminfoparams: | |
|
303 | 304 | start = ''.join(_effect_str(ui, effect) |
|
304 | 305 | for effect in ['none'] + effects.split()) |
|
305 | 306 | stop = _effect_str(ui, 'none') |
@@ -157,6 +157,7 b' class ui(object):' | |||
|
157 | 157 | self.logblockedtimes = False |
|
158 | 158 | # color mode: see mercurial/color.py for possible value |
|
159 | 159 | self._colormode = None |
|
160 | self._terminfoparams = {} | |
|
160 | 161 | |
|
161 | 162 | if src: |
|
162 | 163 | self.fout = src.fout |
@@ -174,6 +175,7 b' class ui(object):' | |||
|
174 | 175 | self.callhooks = src.callhooks |
|
175 | 176 | self.insecureconnections = src.insecureconnections |
|
176 | 177 | self._colormode = src._colormode |
|
178 | self._terminfoparams = src._terminfoparams.copy() | |
|
177 | 179 | |
|
178 | 180 | self.fixconfig() |
|
179 | 181 |
General Comments 0
You need to be logged in to leave comments.
Login now