Last active
September 11, 2016 04:54
-
-
Save adrianratnapala/a33a8c49eeb599e3a84244ad1d0f0267 to your computer and use it in GitHub Desktop.
Generate a (US) ascii table on your terminal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
out = sys.stdout | |
control_codes = [ | |
("NUL", "Null"), | |
("SOH", "Start of Heading"), | |
("STX", "Start of Text"), | |
("ETX", "End of Text"), | |
("EOT", "End of Transmission"), | |
("ENQ", "Enquiry"), | |
("ACK", "Acknowledgement"), | |
("BEL", "Bell"), | |
("BS", "Backspace"), | |
("HT", "Horizontal Tab"), | |
("LF", "Line Feed"), | |
("VT", "Vertical Tab"), | |
("FF", "Form Feed"), | |
("CR", "Carriage Return[g]"), | |
("SO", "Shift Out"), | |
("SI", "Shift In"), | |
("DLE", "Data Link Escape"), | |
("DC1", "Device Control 1 (often XON)"), | |
("DC2", "Device Control 2"), | |
("DC3", "Device Control 3 (often XOFF)"), | |
("DC4", "Device Control 4"), | |
("NAK", "Negative Acknowledgement"), | |
("SYN", "Synchronous Idle"), | |
("ETB", "End of Transmission Block"), | |
("CAN", "Cancel"), | |
("EM", "End of Medium"), | |
("SS", "Substitute"), | |
("ESC", "Escape"), | |
("FS", "File Separator"), | |
("GS", "Group Separator"), | |
("RS", "Record Separator"), | |
("US", "Unit Seprator"), | |
] | |
delete=("DEL", "Delete") | |
def strings(): | |
for k in range(0,32): | |
yield " %4d %3x %-3s" % (k, k, control_codes[k][0]) | |
for k in range(32,127): | |
yield " %4d %3x '%c'" % (k, k, k) | |
k = k+1 | |
yield " %4d %3x %s" % (k, k, delete[0]) | |
def wstrings(n): | |
p = "%%%ds" % n | |
for s in strings(): | |
s = p % s | |
assert len(s) == n | |
yield s | |
def reshape(arr, stride, w): | |
k = 0 | |
n = len(arr) | |
while k + stride * (w-1) < n: | |
yield tuple(arr[k+stride*j] for j in range(0,w)) | |
k += 1 | |
l = list(wstrings(20)) | |
assert len(l) == 128 | |
for t in reshape(l, 32, 4): | |
print(''.join(t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment