mnaberez / py65

Emulate 6502-based microcomputer systems in Python
BSD 3-Clause "New" or "Revised" License
234 stars 68 forks source link

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

Closed larsks closed 7 months 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()
mnaberez commented 3 years ago

What version of Python and Py65 are you using?

mnaberez commented 3 years ago

Pull requests #63, #65 were submitted for this issue.

patricksurry commented 1 year ago

possibly fixed by #78 ?