[Python-ideas] Suggestion: Clear screen command for the REPL

eryk sun eryksun at gmail.com
Thu Sep 29 03:53:47 EDT 2016


On Thu, Sep 29, 2016 at 7:08 AM, Stephan Houben <stephanh42 at gmail.com> wrote:
>
> I just tried with this official Python binary:
> Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit
> (Intel)] on win32
>
> and CTRL-L for sure does clear the window. It just doesn't then move the
> prompt to the top, so you end up with a bunch of empty lines, followed by
> the prompt.

You probably have pyreadline installed. It calls ReadConsoleInputW to
read low-level input records, bypassing the console's normal cooked
read. See the following file that defines the key binding:

https://github.com/pyreadline/pyreadline/blob/1.7/pyreadline/configuration/pyreadlineconfig.ini#L18

Unfortunately pyreadline is broken for non-ASCII input. It ignores the
Alt+Numpad record sequences used for non-ASCII characters.

Without having to implement readline module for Windows (personally, I
don't use it), support for Ctrl+L can be added relatively easily in
3.6+. ReadConsoleW takes a parameter to specify a mask of ASCII
control characters that terminate a read. The control character is
left in the buffer, so code just has to be written that looks for
various control characters to implement features such as a Ctrl+L
clear screen.


More information about the Python-ideas mailing list