-
Notifications
You must be signed in to change notification settings - Fork 19
/
termpad.py
47 lines (37 loc) · 1.25 KB
/
termpad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import colorama
import os
import colors
from gridgets import ARROWS, MENU
from griode import Grid
class ASCIIGrid(Grid):
def __init__(self, griode, fd_in, fd_out):
self.fd_in = fd_in
self.fd_out = fd_out
self.surface = ASCIISurface(self)
Grid.__init__(self, griode, "tty")
class ASCIISurface(object):
def __init__(self, grid):
self.grid = grid
self.write(colorama.ansi.clear_screen())
def __iter__(self):
return (ARROWS + MENU + [(row, column)
for row in range(1, 9)
for column in range(1, 9)]).__iter__()
def write(self, s):
os.write(self.grid.fd_out, s.encode("utf-8"))
def __setitem__(self, led, color):
# This is a janky map but it will do for now
char = {
palette.BLACK: " ",
colors.PINK_HI: "X",
colors.ROSE: ".",
colors.GREY_LO: ".",
}.get(color, "o")
if isinstance(led, tuple):
row, column = led
else:
row = 10
column = (ARROWS+MENU).index(led) + 1
pos = colorama.Cursor.POS(column*2, 11-row)
bottom = colorama.Cursor.POS(1, 12)
self.write(pos + char + bottom)