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",
"request": "launch",
"program": "dopey.py",
"args": ["./helloworld.bf"],
"args": ["./test.bf"],
"console": "integratedTerminal"
}
]

View File

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