This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, ezio.melotti, paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Date 2020-09-24.22:27:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1600986460.74.0.18301283333.issue41849@roundup.psfhosted.org>
In-reply-to
Content
> The biggest risk here is that we have to emulate GNU readline for 
> compatibility, which severely limits the data that can be passed 
> through, and also forces multiple encoding/decoding passes. 

I'm not suggesting to disable the console's line-input and echo-input modes and implement our own line editor. If people don't like the built-in line editor that the console provides, they can use pyreadline, which directly uses the console's low-level API via ctypes.

Here's an example of what I would like to just work by default in Python:

    import sys
    import win32console

    def write_input(h, s):
         records = []
         for c in s:
             b = c.encode('utf-16le')
             for i in range(0, len(b), 2):
                 r = win32console.PyINPUT_RECORDType(win32console.KEY_EVENT)
                 r.KeyDown = True
                 r.RepeatCount = 1
                 r.Char = b[i:i+2].decode('utf-16le', 'surrogatepass')
                 records.append(r)
         h.WriteConsoleInput(records)

    def write_and_read_line(s):
        if '\r' not in s:
            s += '\r'
        h = win32console.GetStdHandle(win32console.STD_INPUT_HANDLE)
        mode = h.GetConsoleMode()
        h.SetConsoleMode(mode & ~win32console.ENABLE_ECHO_INPUT)
        try:
            write_input(h, s)
            line = sys.stdin.readline()
        finally:
            h.SetConsoleMode(mode)
        return line

    >>> src_line = 'a' * 32765 + '\r'
    >>> res_line = write_and_read_line(src_line)
    >>> assert res_line == src_line.replace('\r', '\n')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AssertionError
    >>> len(res_line)
    511
    >>> res_line[:5], res_line[-5:]
    ('aaaaa', 'aaaa\n')


Currently the ReadConsoleW buffer in read_console_w is capped at 512 (BUFSIZ) characters. With the console's processed-input mode enabled, it writes a trailing CRLF instead of the raw CR. So the user is limited to typing or pasting just 510 characters on a single line. 

I was only thinking to increase the default maximum size up to 32K in read_console_w -- removing the fixed BUFSIZ aspect of the implementation in favor of capping the buffer used at BUFMAX. In practice this also requires similar default increases for the BufferedReader size and TextIOWrapper chunk size.
History
Date User Action Args
2020-09-24 22:27:40eryksunsetrecipients: + eryksun, paul.moore, tim.golden, ezio.melotti, zach.ware, serhiy.storchaka, steve.dower
2020-09-24 22:27:40eryksunsetmessageid: <1600986460.74.0.18301283333.issue41849@roundup.psfhosted.org>
2020-09-24 22:27:40eryksunlinkissue41849 messages
2020-09-24 22:27:40eryksuncreate