From d3e72e27be1c7fdbb4cdf9d34eb9e94c8a8aa566 Mon Sep 17 00:00:00 2001 From: Giovani Date: Tue, 15 Jun 2021 17:28:57 -0400 Subject: [PATCH] fix: address terminal input problem --- .vscode/launch.json | 2 +- dopey.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 85a9464..d6f56e0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "python", "request": "launch", "program": "dopey.py", - "args": ["./helloworld.bf"], + "args": ["./test.bf"], "console": "integratedTerminal" } ] diff --git a/dopey.py b/dopey.py index e814891..78b54cb 100644 --- a/dopey.py +++ b/dopey.py @@ -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: