59 lines
1.7 KiB
Python
Executable File
59 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf8 -*-
|
|
|
|
import sys
|
|
from unicodedata import name
|
|
|
|
chars = (r""" !"#$%&'()*+,-./0123456789:;<=>?""" +
|
|
r"""@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_""" +
|
|
r"""`abcdefghijklmnopqrstuvwxyz{|}~ """ +
|
|
r"""ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒ""" +
|
|
r"""áíóúñѪº¿⌐¬½¼¡«»ÃãĨĩÕõŨũIJij¾∽◇‰¶§""" +
|
|
r"""▂▚▆▔◾▇▎▞▊▕▉▨▧▼▲▶◀⧗⧓▘▗▝▖▒Δǂω█▄▌▐▀""" +
|
|
r"""αβΓπΣσμτΦθΩδ∞φ∈∩≡±≥≤⌠⌡÷≈°∙‐√ⁿ²◾■""" +
|
|
r""" ☺☻♥♦♣♠·◘○◙♂♀♪♬☼╂┻┳┫┣╋┃━┏┓┗┛╳╱╲┿""")
|
|
|
|
def msxchars():
|
|
"""
|
|
yields tuples in the form (msx code, unicode character)
|
|
"""
|
|
for i in range(32):
|
|
yield (i, chr(i))
|
|
for i in range(32,256):
|
|
if i == 127:
|
|
yield (i, chr(i))
|
|
else:
|
|
yield (i, chars[i - 32])
|
|
for i in range(65,96):
|
|
yield (256 + i, chars[160 + i])
|
|
|
|
charmap = {}
|
|
|
|
for m,c in msxchars():
|
|
charmap[m] = c
|
|
|
|
if len(sys.argv) < 2:
|
|
while True:
|
|
b = sys.stdin.buffer.read(1)
|
|
if len(b) == 0:
|
|
break
|
|
code = b[0]
|
|
if code == 1:
|
|
c = sys.stdin.buffer.read(1)
|
|
if len(b) == 0:
|
|
sys.stdout.write('\x01')
|
|
break
|
|
code = 256 + c[0]
|
|
char = charmap[code]
|
|
sys.stdout.write(char)
|
|
|
|
if sys.argv[1] == '-l':
|
|
for m,c in msxchars():
|
|
if m < 32 or m == 127:
|
|
continue
|
|
try:
|
|
n = name(c)
|
|
except ValueError:
|
|
n = ""
|
|
print(m,ord(c),c,n)
|