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.

classification
Title: Implement interactive hotkey, Ctrl+L to clear the console in Windows.
Type: enhancement Stage:
Components: Windows Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, mixmastamyk, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-12-28 19:12 by mixmastamyk, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg383917 - (view) Author: Mike Miller (mixmastamyk) Date: 2020-12-28 19:12
The Ctrl+L as clear-screen hotkey is supported just about everywhere, Unix and Windows, with the exceptions of cmd.exe and python.exe interactive mode.

As the legacy cmd.exe can be easily replaced, that leaves python.exe.  Likely needs to be configured via readline or its analog used under Windows.

Documenting it would be good too.  Am happy to help, write, or test.
msg383920 - (view) Author: Mike Miller (mixmastamyk) Date: 2020-12-28 19:30
I found an implementation of this for Windows in case it is needed.  Not sure if it is the best way to do it, as the Console API is rather clumsy.  However this one works to my knowledge:

https://github.com/tartley/colorama/blob/master/colorama/winterm.py#L111
msg383927 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-12-28 20:30
> As the legacy cmd.exe can be easily replaced, that leaves python.exe. 

python.exe is a console application, which attaches to a console session. Since Windows 7, each console session is hosted by an instance of conhost.exe.

The CMD shell (cmd.exe) is a console application, the same as python.exe. It doesn't matter whether Python allocates a new console or inherits it from another process such as cmd.exe.

> Likely needs to be configured via readline or its analog used under 
> Windows.

pyreadline implements readline for the Windows console API via ctypes. It supports Ctrl+L to clear the screen, including the scrollback. PSReadLine in PowerShell implements Ctrl+L without clearing the scrollback. That's a better example to follow if someone wants to take up the ambitious project of supporting readline for Windows in the standard library.
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86937
2020-12-28 20:30:47eryksunsetnosy: + eryksun
messages: + msg383927
2020-12-28 19:30:32mixmastamyksetmessages: + msg383920
2020-12-28 19:12:23mixmastamykcreate