Created
November 4, 2022 17:16
-
-
Save guidoism/a511daa9d82c40c00d8baf96db507930 to your computer and use it in GitHub Desktop.
Keymap Status Viewer
This file contains hidden or 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
["TAB q w e r t y u i o p BS \nCTL a s d f g h j k l :; RET\nSFT z x c v b n m , . / \u25cc\n \u25cc \u25cc OPT CMD M1 M3 \u2423 M2 \u25cc \u25cc \u25cc \u25cc", " ~ ! @ # $ % ^ 7 8 9 \u25cc \u25cc\n \u25cc \" & * _ \u25cc + 4 5 6 ' |\n \u25cc \u25cc \u25cc \u25cc \u25cc . 0 1 2 3 / \u25cc\n \u25cc \u25cc OPT CMD \u25c9 \u25cc \u25cc M5 \u25cc \u25cc \u25cc \u25cc", " ` \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc BS\n \u25cc [ ] ( ) \u25cc \u25cc - = \u25cc \u25cc \\\n \u25cc < > { } \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc OPT CMD M4 \u25cc \u25cc \u25c9 \u25cc \u25cc \u25cc \u25cc", "ESC \u03bb\u2190 \u03bb\u2192 \u00b6\u2190 \u00b6\u2192 \u25cc \u25cc P\u2191 \u2191 P\u2193 \u25cc \u25cc\n \u25cc S\u2190 S\u2192 W\u2190 W\u2192 BEG \u25cc \u2190 \u2193 \u2192 CYC \u25cc\n \u25cc \u2303z \u2303x \u2303c \u2303v \u25cc \u25cc HME \u25cc END \u25cc \u25cc\n \u25cc \u25cc OPT CMD M1 \u25c9 \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc", " \u25cc F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \u25cc\n \u25cc \u222bC \u222bD \u222bS \u222bE \u222bP Bu0 Bu1 Bu2 Bu3 Bu4 \u25cc\n \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc OPT CMD \u25c9 M6! \u25cc \u25c9 \u25cc \u25cc \u25cc \u25cc", " \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc OPT CMD \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc", "QWE \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\nCOL BT4 BT3 BT2 BT1 BTC \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc OPT CMD \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc", "TAB q w f p g j l u y :; BS\nCTL a r s t d h n e i o RET\nSFT z x c v b k m , . / \u25cc\n \u25cc \u25cc OPT CMD M1 M3 \u2423 M2 \u25cc \u25cc \u25cc \u25cc", " \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc\n \u25cc \u25cc OPT CMD \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc \u25cc", ""] |
This file contains hidden or 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
import json, subprocess, serial, re, rich, rich.console, os | |
updated = os.stat('layers.json').st_mtime | |
layers_in = json.load(open('layers.json')) | |
col_color = { | |
0: '[cyan]', | |
1: '[bold cyan]', | |
2: '[bold magenta1]', | |
3: '[bold green1]', | |
4: '[bold turquoise2]', | |
5: '[turquoise2]', | |
6: '[turquoise2]', | |
7: '[bold turquoise2]', | |
8: '[bold green1]', | |
9: '[bold magenta1]', | |
10: '[bold cyan]', | |
11: '[cyan]', | |
} | |
layers = [] | |
for l in layers_in: | |
rows = [] | |
for r in l.split('\n'): | |
row = [] | |
for i, m in enumerate(re.findall(r'(\s*\S+\s*)', r)): | |
if '◌' in m: | |
row.append('[dim]') | |
row.append(m) | |
row.append('[/]') | |
else: | |
row.append(col_color[i]) | |
row.append(m) | |
row.append('[/]') | |
rows.append(''.join(row)) | |
layers.append('\n'.join(rows)) | |
p = subprocess.run(['discotool', 'json'], capture_output=True) | |
devs = json.loads(p.stdout) | |
vol = lambda d: {v['name'] for v in d['volumes']} | |
path = [d['ports'][0]['dev'] for d in devs if 'KEEB-1' in vol(d)][0] | |
ser = serial.Serial(path) | |
con = rich.console.Console() | |
while s := ser.readline(): | |
if m := re.match(r'Layer: (\d+)', s.decode()): | |
n = int(m.group(1)) | |
con.clear() | |
con.print(layers[n]) | |
if os.stat('layers.json').st_mtime > updated: | |
updated = os.stat('layers.json').st_mtime | |
layers = json.load(open('layers.json')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment