fibonaccios/lib/console.py

22 lines
511 B
Python
Raw Normal View History

2022-11-30 14:27:12 -08:00
def read(console, buffer):
char = console.read(1)
if char == b'\x08':
if buffer:
console.write(b'\x08 \x08')
buffer.pop()
return
elif char == b'\n':
console.write(b'\n')
data = b''.join(buffer)
buffer.clear()
return data
elif len(char) == 1:
console.write(char)
buffer.append(char)
else:
return None
2022-11-30 19:33:05 -08:00
def write_str(console, string, encoding="utf-8"):
console.write(string.encode(encoding))