Mercurial > hg-stable
changeset 31117:8903f67b9ca8
color: move 'terminfosetup' into the core module
Another step closer to have all the logic living in core
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 22 Dec 2016 14:17:52 +0100 |
parents | b44ab288358e |
children | 9021a94a7dbf |
files | hgext/color.py mercurial/color.py |
diffstat | 2 files changed, 40 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/color.py Sat Feb 25 21:13:59 2017 -0500 +++ b/hgext/color.py Thu Dec 22 14:17:52 2016 +0100 @@ -192,45 +192,6 @@ # leave the attribute unspecified. testedwith = 'ships-with-hg-core' -def _terminfosetup(ui, mode): - '''Initialize terminfo data and the terminal if we're in terminfo mode.''' - - # If we failed to load curses, we go ahead and return. - if curses is None: - return - # Otherwise, see what the config file says. - if mode not in ('auto', 'terminfo'): - return - - for key, val in ui.configitems('color'): - if key.startswith('color.'): - newval = (False, int(val), '') - color._terminfo_params[key[6:]] = newval - elif key.startswith('terminfo.'): - newval = (True, '', val.replace('\\E', '\x1b')) - color._terminfo_params[key[9:]] = newval - try: - curses.setupterm() - except curses.error as e: - color._terminfo_params.clear() - return - - for key, (b, e, c) in color._terminfo_params.items(): - if not b: - continue - if not c and not curses.tigetstr(e): - # Most terminals don't support dim, invis, etc, so don't be - # noisy and use ui.debug(). - ui.debug("no terminfo entry for %s\n" % e) - del color._terminfo_params[key] - if not curses.tigetstr('setaf') or not curses.tigetstr('setab'): - # Only warn about missing terminfo entries if we explicitly asked for - # terminfo mode. - if mode == "terminfo": - ui.warn(_("no terminfo entry for setab/setaf: reverting to " - "ECMA-48 color\n")) - color._terminfo_params.clear() - def _modesetup(ui, coloropt): if coloropt == 'debug': return 'debug' @@ -284,7 +245,7 @@ elif realmode == 'ansi': color._terminfo_params.clear() elif realmode == 'terminfo': - _terminfosetup(ui, mode) + color._terminfosetup(ui, mode) if not color._terminfo_params: ## FIXME Shouldn't we return None in this case too? modewarn()
--- a/mercurial/color.py Sat Feb 25 21:13:59 2017 -0500 +++ b/mercurial/color.py Thu Dec 22 14:17:52 2016 +0100 @@ -118,6 +118,45 @@ def loadcolortable(ui, extname, colortable): _styles.update(colortable) +def _terminfosetup(ui, mode): + '''Initialize terminfo data and the terminal if we're in terminfo mode.''' + + # If we failed to load curses, we go ahead and return. + if curses is None: + return + # Otherwise, see what the config file says. + if mode not in ('auto', 'terminfo'): + return + + for key, val in ui.configitems('color'): + if key.startswith('color.'): + newval = (False, int(val), '') + _terminfo_params[key[6:]] = newval + elif key.startswith('terminfo.'): + newval = (True, '', val.replace('\\E', '\x1b')) + _terminfo_params[key[9:]] = newval + try: + curses.setupterm() + except curses.error as e: + _terminfo_params.clear() + return + + for key, (b, e, c) in _terminfo_params.items(): + if not b: + continue + if not c and not curses.tigetstr(e): + # Most terminals don't support dim, invis, etc, so don't be + # noisy and use ui.debug(). + ui.debug("no terminfo entry for %s\n" % e) + del _terminfo_params[key] + if not curses.tigetstr('setaf') or not curses.tigetstr('setab'): + # Only warn about missing terminfo entries if we explicitly asked for + # terminfo mode. + if mode == "terminfo": + ui.warn(_("no terminfo entry for setab/setaf: reverting to " + "ECMA-48 color\n")) + _terminfo_params.clear() + def configstyles(ui): for status, cfgeffects in ui.configitems('color'): if '.' not in status or status.startswith(('color.', 'terminfo.')):