Skip to content

Instantly share code, notes, and snippets.

@encukou
Last active July 9, 2025 00:41
Show Gist options
  • Save encukou/93fdc72f424c5451ca7c3c848edf4754 to your computer and use it in GitHub Desktop.
Save encukou/93fdc72f424c5451ca7c3c848edf4754 to your computer and use it in GitHub Desktop.
"""Super-minimal 'curses'; values _pyrepl needs hardcoded & non-portable.
Use this instead of _pyrepl._minimal_curses; test well with *your* terminal.
"""
class error(Exception):
pass
OK = 0
ERR = -1
def setupterm(termstr, fd):
pass
def tigetstr(cap):
if not isinstance(cap, bytes):
cap = cap.encode("ascii")
try:
return {
b'bel': b'\x07',
b'civis': b'\x1b[?25l',
b'clear': b'\x1b[H\x1b[2J',
b'cnorm': b'\x1b[?12l\x1b[?25h',
b'cub': b'\x1b[%p1%dD',
b'cub1': b'\x08',
b'cud': b'\x1b[%p1%dB',
b'cud1': b'\n',
b'cuf': b'\x1b[%p1%dC',
b'cuf1': b'\x1b[C',
b'cup': b'\x1b[%i%p1%d;%p2%dH',
b'cuu': b'\x1b[%p1%dA',
b'cuu1': b'\x1b[A',
b'dch1': b'\x1b[P',
b'dch': b'\x1b[%p1%dP',
b'el': b'\x1b[K',
b'hpa': b'\x1b[%i%p1%dG',
b'ich': b'\x1b[%p1%d@',
b'ind': b'\n',
b'ri': b'\x1bM',
b'rmkx': b'\x1b[?1l\x1b>',
b'smkx': b'\x1b[?1h\x1b=',
b'kdch1': b'\x1b[3~',
b'kcud1': b'\x1bOB',
b'kend': b'\x1bOF',
b'kent': b'\x1bOM',
b'khome': b'\x1bOH',
b'kich1': b'\x1b[2~',
b'kcub1': b'\x1bOD',
b'knp': b'\x1b[6~',
b'kpp': b'\x1b[5~',
b'kcuf1': b'\x1bOC',
b'kcuu1': b'\x1bOA',
b'kf1': b'\x1bOP',
b'kf2': b'\x1bOQ',
b'kf3': b'\x1bOR',
b'kf4': b'\x1bOS',
b'kf5': b'\x1b[15~',
b'kf6': b'\x1b[17~',
b'kf7': b'\x1b[18~',
b'kf8': b'\x1b[19~',
b'kf9': b'\x1b[20~',
b'kf10': b'\x1b[21~',
b'kf11': b'\x1b[23~',
b'kf12': b'\x1b[24~',
b'kf13': b'\x1b[1;2P',
b'kf14': b'\x1b[1;2Q',
b'kf15': b'\x1b[1;2R',
b'kf16': b'\x1b[1;2S',
b'kf17': b'\x1b[15;2~',
b'kf18': b'\x1b[17;2~',
b'kf19': b'\x1b[18;2~',
b'kf20': b'\x1b[19;2~',
}[cap]
except KeyError:
return None
def tparm(s, p1=0, p2=0, *params):
return (
s
.replace(b'%i%p1%d', str(p1 + 1).encode('ascii'))
.replace(b'%p1%d', str(p1 if p1 else '').encode('ascii'))
.replace(b'%p2%d', str(p2 if p2 else '').encode('ascii'))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment