scotws / TaliForth2

A Subroutine Threaded Code (STC) ANS-like Forth for the 65c02
Other
86 stars 23 forks source link

bytes-vs-string issue in utils/console.py #266

Closed larsks closed 3 years ago

larsks commented 3 years ago

Attempting to use the assemble command in the monitor will fail in utils/console.py in line_input(), because there is an attempt to concatenate the byte string returned by getch() with the unicode string line (see my comments, below):

def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout):
    stdout.write(prompt)
    line = '' # BUG: THIS IS A (UNICODE) STRING
    while True:
        char = getch(stdin)  # BUG: THIS RETURNS A BYTESTRING
        code = ord(char)
        breakpoint()
        if char in ("\n", "\r"):
            break
        elif code in (0x7f, 0x08):  # backspace
            if len(line) > 0:
                line = line[:-1]
                stdout.write("\r%s\r%s%s" %
                             (' ' * (len(prompt + line) + 5), prompt, line))
        elif code == 0x1b:  # escape
            pass
        else:
            line += char # BUG: THIS FAILS BECAUSE YOU CAN'T CONCATENATE A UNICODE STRING + BYTE STRING
            stdout.write(char)
            stdout.flush()
larsks commented 3 years ago

Oops, wrong repo.