Added character input to tty machine
This commit is contained in:
parent
5ac213a779
commit
c655bb8982
|
@ -4,8 +4,33 @@
|
||||||
from .emulator import Device
|
from .emulator import Device
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Windows
|
||||||
|
import msvcrt
|
||||||
|
def getch() -> int:
|
||||||
|
return msvcrt.getch()[0]
|
||||||
|
except ImportError:
|
||||||
|
# Unix
|
||||||
|
import sys
|
||||||
|
import tty, termios
|
||||||
|
def getch() -> int:
|
||||||
|
fd = sys.stdin.fileno()
|
||||||
|
old_settings = termios.tcgetattr(fd)
|
||||||
|
try:
|
||||||
|
tty.setraw(fd)
|
||||||
|
return sys.stdin.read(1).encode('utf-8')[0]
|
||||||
|
finally:
|
||||||
|
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||||
|
|
||||||
|
|
||||||
class tty(Device):
|
class tty(Device):
|
||||||
|
|
||||||
|
def __getitem__(self, index: int) -> int:
|
||||||
|
if index & 0xf == 0xd: return 0
|
||||||
|
elif index & 0xf == 0xe: return 0
|
||||||
|
elif index & 0xf == 0xf: return getch()
|
||||||
|
else: return 0
|
||||||
|
|
||||||
def __setitem__(self, index: int, value: int):
|
def __setitem__(self, index: int, value: int):
|
||||||
if index & 0xf == 0xd:
|
if index & 0xf == 0xd:
|
||||||
if value & 0x800:
|
if value & 0x800:
|
||||||
|
|
Loading…
Reference in New Issue