#!/usr/bin/python2 -tt # vim:set fileencoding=utf-8 from subprocess import * import sys import os, select special = { #Ꮉ ꙮ # Tree - ᎙ '\xf1': u'\u1399', # Fountain ♈ '\xf4': u'\u2648', # water ♒ 2652 ≋ 224b '\xf7': u'\u224b', #boulder -● #boulder -⭓ #'\xe1': u'\u25cf', '\xe1': u'\u2B53', # hole - ◯ '\x80': u'\u25ef', #beartrap - Φ '\x81': u'\u03A6', #bug - ᛤ '\x82': u'\u16E4', # Unicorn/Horse - ♞ '\x83': u'\u265e', # level teleporter/magic portal - ⎗ '\x84': u'\u2397', # arrow trap - ➴ '\x85': u'\u27b4', # open door - ∏ '\x86': u'\u220f', # closed door - ⧮ '\x87': u'\u29ee', # ring - ⊚ 229a ⚬ 26ac '\x88': u'\u26ac', # ghost - ☄ 2604 '\x89': u'\u2604', # down entrance ⬎ '\x3e': u'\u2b0e', # up entrance ⬑ '\x3c': u'\u2b11', # Spiderweb: sun symbol - ⎈ '\xe2': u'\u2388', #⸎ - 2e0e - good elemental? #〠 - monkey? 3020 Keystone kop maybe - if 4b is keystone kop, needs remap first #'\x4b': u'\u3020', # ٥ - egg? 0665 # Special cases for rogue levels '\x01': u'\u263b', # human, elf - smiley ☺ # use smiley for all humans ☺ - ☻ is the alternate \u263b '\x40': u'\u263b', # human, elf - smiley '\x04': u'\u2666', # trap, web - dimaond # Grave - ♰ '\xef': u'\u2670', # 4de1 screws up rendering. trying ≣ instead '\xfc': u'\u2263' # These are supposed to be used on rogue levels, but don't appear # to be used when I try them... #'\x05': u'\u2663', # food - clubs #'\x0c': u'\u2640', # amulet - female #'\x0e': u'\u266b', # scroll - note #'\x0f': u'\u263c', # gold, gems - sun #'\x18': u'\u2191', # weapon - up arrow } if len(sys.argv) < 2: print "usage: ibmfilter [command]" print "Runs command in a subshell and translates its output from ibm473 codepage to UTF-8." sys.exit(0) handle = Popen(sys.argv[1:], stdout=PIPE, bufsize=1) buf = handle.stdout.read(1) while buf != '': if buf in special: out = special[buf] else: out = buf.decode('ibm437') writeable = select.select([], [sys.stdout], [], 5)[1] if not writeable: os.kill(handle.pid) os.system('reset') raise Exception("Timed out while waiting for stdout to be writeable...") sys.stdout.write(out.encode("UTF-8")) buf = handle.stdout.read(1) handle.wait()