fix: address terminal input problem
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
10
dopey.py
10
dopey.py
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user