Skip to content

Instantly share code, notes, and snippets.

@0x5742
Created April 6, 2016 18:37
Show Gist options
  • Select an option

  • Save 0x5742/3f941f191f58f046125949505738537e to your computer and use it in GitHub Desktop.

Select an option

Save 0x5742/3f941f191f58f046125949505738537e to your computer and use it in GitHub Desktop.
Unicode character viewing tool
#!/usr/bin/env python
import unicodedata, sys
def uninamenum(c):
u = 'U+%04X' % ord(c)
try:
name = unicodedata.name(c)
except:
return u
else:
return u + ' ' + name.title()
import ctypes
wcwidth = ctypes.CDLL(None).wcwidth
wcwidth.argtypes = [ctypes.c_wchar]
def printable_char(c):
return (c if wcwidth(c) >= 0 else '')
def describe(chunk):
return '\n'.join('%s\t%s' % (printable_char(c), uninamenum(c))
for c in chunk.rstrip('\n'))
print('\n\n'.join(filter(None, map(describe, (sys.stdin if len(sys.argv) == 1
else sys.argv[1:])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment