Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHG483cafc3762a: py3: make sure curses.tigetstr() first argument is a str
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
durin42 |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
curses.setupterm() | curses.setupterm() | ||||
except curses.error as e: | except curses.error as e: | ||||
ui._terminfoparams.clear() | ui._terminfoparams.clear() | ||||
return | return | ||||
for key, (b, e, c) in ui._terminfoparams.copy().items(): | for key, (b, e, c) in ui._terminfoparams.copy().items(): | ||||
if not b: | if not b: | ||||
continue | continue | ||||
if not c and not curses.tigetstr(e): | if not c and not curses.tigetstr(pycompat.sysstr(e)): | ||||
# Most terminals don't support dim, invis, etc, so don't be | # Most terminals don't support dim, invis, etc, so don't be | ||||
# noisy and use ui.debug(). | # noisy and use ui.debug(). | ||||
ui.debug("no terminfo entry for %s\n" % e) | ui.debug("no terminfo entry for %s\n" % e) | ||||
del ui._terminfoparams[key] | del ui._terminfoparams[key] | ||||
if not curses.tigetstr('setaf') or not curses.tigetstr('setab'): | if not curses.tigetstr(r'setaf') or not curses.tigetstr(r'setab'): | ||||
# Only warn about missing terminfo entries if we explicitly asked for | # Only warn about missing terminfo entries if we explicitly asked for | ||||
# terminfo mode and we're in a formatted terminal. | # terminfo mode and we're in a formatted terminal. | ||||
if mode == "terminfo" and formatted: | if mode == "terminfo" and formatted: | ||||
ui.warn(_("no terminfo entry for setab/setaf: reverting to " | ui.warn(_("no terminfo entry for setab/setaf: reverting to " | ||||
"ECMA-48 color\n")) | "ECMA-48 color\n")) | ||||
ui._terminfoparams.clear() | ui._terminfoparams.clear() | ||||
def setup(ui): | def setup(ui): | ||||
try: | try: | ||||
attr, val, termcode = ui._terminfoparams[effect] | attr, val, termcode = ui._terminfoparams[effect] | ||||
except KeyError: | except KeyError: | ||||
return '' | return '' | ||||
if attr: | if attr: | ||||
if termcode: | if termcode: | ||||
return termcode | return termcode | ||||
else: | else: | ||||
return curses.tigetstr(val) | return curses.tigetstr(pycompat.sysstr(val)) | ||||
elif bg: | elif bg: | ||||
return curses.tparm(curses.tigetstr('setab'), val) | return curses.tparm(curses.tigetstr(r'setab'), val) | ||||
else: | else: | ||||
return curses.tparm(curses.tigetstr('setaf'), val) | return curses.tparm(curses.tigetstr(r'setaf'), val) | ||||
def _mergeeffects(text, start, stop): | def _mergeeffects(text, start, stop): | ||||
"""Insert start sequence at every occurrence of stop sequence | """Insert start sequence at every occurrence of stop sequence | ||||
>>> s = _mergeeffects(b'cyan', b'[C]', b'|') | >>> s = _mergeeffects(b'cyan', b'[C]', b'|') | ||||
>>> s = _mergeeffects(s + b'yellow', b'[Y]', b'|') | >>> s = _mergeeffects(s + b'yellow', b'[Y]', b'|') | ||||
>>> s = _mergeeffects(b'ma' + s + b'genta', b'[M]', b'|') | >>> s = _mergeeffects(b'ma' + s + b'genta', b'[M]', b'|') | ||||
>>> s = _mergeeffects(b'red' + s, b'[R]', b'|') | >>> s = _mergeeffects(b'red' + s, b'[R]', b'|') |