py65 icon indicating copy to clipboard operation
py65 copied to clipboard

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

Open larsks opened this issue 4 years ago • 3 comments

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 avatar Jan 13 '21 03:01 larsks

What version of Python and Py65 are you using?

mnaberez avatar Jan 13 '21 03:01 mnaberez

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

mnaberez avatar Jan 13 '21 03:01 mnaberez

possibly fixed by #78 ?

patricksurry avatar Sep 14 '23 22:09 patricksurry