[spam][crazy][ot][crazy][spam][crazy]
Undescribed Horrific Abuse, One Victim & Survivor of Many
gmkarl at gmail.com
Sun Nov 20 11:19:38 PST 2022
Focusing on a dot can seem non-simple when you are computer code.
I made this static `term` class, with methods `clear`, `write_at`,
`where`, and `size`:
class term:
import curses
import sys, tty, termios
curses.setupterm()
_cup = curses.tigetstr('cup')
_clear = curses.tigetstr('clear').decode()
_csi = '\x1b['
_dsr_cpr = _csi + '6n'
@classmethod
def clear(cls):
x, y = cls.where()
print(cls._clear, end='', flush=True)
cls.write_at(x, y)
@classmethod
def write_at(cls, x, y, *text):
print(cls.curses.tparm(cls._cup, y, x).decode(), end='')
print(*text, end='', flush=True)
@classmethod
def size(cls):
return cls.curses.tigetnum('cols'), cls.curses.tigetnum('rows')
@classmethod
def where(cls):
print(cls._dsr_cpr, end='', flush=True)
_, row, col = cls._read_through(cls.sys.stdin, cls._csi, ';', 'R')
return int(col) - 1, int(row) - 1
@classmethod
def _read_through(cls, file, *delimiters, include=False):
fileno = file.fileno()
tattr = cls.termios.tcgetattr(fileno)
cls.tty.setcbreak(fileno, cls.termios.TCSANOW)
try:
datas = []
for delimiter in delimiters:
data = type(delimiter)()
while not data.endswith(delimiter):
data += file.read(1)
if not include:
data = data[:-len(delimiter)]
datas.append(data)
if len(datas) == 1:
return datas[0]
else:
return datas
finally:
cls.termios.tcsetattr(fileno, cls.termios.TCSANOW, tattr)
Then I can make this small environment class, and have it label a
period as I imagined:
import time
class environment:
def make_period_at(self, x, y):
term.write_at(x, y, '.')
def label_as_period(self, x, y):
term.write_at(x + 2, y, '<- this is a period')
def wait(self, seconds):
time.sleep(seconds)
environment = environment()
x, y = term.where()
term.clear()
environment.wait(1)
environment.make_period_at(x, y)
environment.label_as_period(x, y)
environment.wait(4)
More information about the cypherpunks
mailing list