fix: address terminal input problem

This commit is contained in:
2021-06-15 17:28:57 -04:00
parent d100ffd49f
commit d3e72e27be
2 changed files with 7 additions and 5 deletions

2
.vscode/launch.json vendored
View File

@@ -9,7 +9,7 @@
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"program": "dopey.py", "program": "dopey.py",
"args": ["./helloworld.bf"], "args": ["./test.bf"],
"console": "integratedTerminal" "console": "integratedTerminal"
} }
] ]

View File

@@ -1,6 +1,5 @@
import sys import sys
from io import TextIOWrapper from io import TextIOWrapper
from blessed import Terminal
class MismatchBracketException(Exception): class MismatchBracketException(Exception):
""" TODO line number and column """ """ TODO line number and column """
@@ -10,6 +9,7 @@ class Memory:
BUFFER_SIZE = 30_000 BUFFER_SIZE = 30_000
buffer = [0 for _ in range(BUFFER_SIZE)] buffer = [0 for _ in range(BUFFER_SIZE)]
pointer = 0 pointer = 0
input_buffer = []
@classmethod @classmethod
def get_pointer(cls) -> int: def get_pointer(cls) -> int:
@@ -26,7 +26,6 @@ class Operation:
OPEN_LOOP = "[" OPEN_LOOP = "["
CLOSE_LOOP = "]" CLOSE_LOOP = "]"
terminal = Terminal()
loop_stack = [] loop_stack = []
@classmethod @classmethod
@@ -68,8 +67,11 @@ class Operation:
@classmethod @classmethod
def input(cls, _) -> None: def input(cls, _) -> None:
with cls.terminal.cbreak(): if not len(Memory.input_buffer):
Memory.buffer[Memory.get_pointer()] = ord(cls.terminal.inkey()) input_ = input()
Memory.input_buffer += list(input_)
if len(Memory.input_buffer):
Memory.buffer[Memory.get_pointer()] = ord(Memory.input_buffer.pop(0))
@classmethod @classmethod
def open_loop(cls, file: TextIOWrapper) -> None: def open_loop(cls, file: TextIOWrapper) -> None: