#!/usr/bin/env python3 conversions = { "f": 5792, "u": 5794, "th": 5798, "o": 5801, "r": 5809, "ch": 5811, "c": 5811, "g": 5815, "w": 5817, "v": 5817, "h": 5819, "n": 5822, "i": 5825, "j": 5828, "yo": 5831, "p": 5832, "x": 5833, "s": 5835, "t": 5839, "b": 5842, "e": 5846, "m": 5847, "l": 5850, "ng": 5853, "d": 5854, "oe": 5855, "a": 5800, "ae": 5803, "y": 5795, "ea": 5856, "k": 5859, "ga": 5816, "q": 5859, "F": 5792, "U": 5794, "TH": 5798, "O": 5801, "R": 5809, "CH": 5811, "C": 5811, "G": 5815, "W": 5817, "V": 5817, "H": 5819, "N": 5822, "I": 5825, "J": 5828, "YO": 5831, "P": 5832, "X": 5833, "S": 5835, "T": 5839, "B": 5842, "E": 5846, "M": 5847, "L": 5850, "NG": 5853, "D": 5854, "OE": 5855, "A": 5800, "AE": 5803, "Y": 5795, "EA": 5856, "K": 5859, "GA": 5816, "Q": 5859, "Th": 5798, "Ch": 5811, "Yo": 5831, "Ng": 5853, "Oe": 5855, "Ae": 5803, "Ea": 5856, "Ga": 5816, "tH": 5798, "cH": 5811, "yO": 5831, "nG": 5853, "oE": 5855, "aE": 5803, "eA": 5856, "gA": 5816, } import sys def next_char(): return sys.stdin.read(1) def print_conversion(s): code = conversions.get(s) if code: return chr(code) else: return s import re def complete_eseq(so_far): return re.fullmatch( "\x1b(?:" + "(?:" + "(?:\]\d;)|" + "(?:#\d)|" + "(?:\dn)|" + "(?:\d+;\d+R)|" + "[NO=>DME78HcFGABCD\d+;\d+[mhlt])" + ")))", so_far) def convert(): last = next_char() print(print_conversion(last), end="") while last != "": this = next_char() if this == "\x1b": so_far = this ch = None while not complete_eseq(so_far) and ch != '': ch = next_char() so_far += ch print(so_far, end="") sys.stdout.flush() last = None continue if last and conversions.get(last + this): print(f"\b{print_conversion(last + this)}", end="") else: print(print_conversion(this), end="") sys.stdout.flush() last = this try: convert() except Exception as e: print(e) exit()