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, gvanrossum, keeely, rhettinger, steve.dower, terry.reedy
Date 2021-11-27.23:04:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638054299.82.0.48791171787.issue45870@roundup.psfhosted.org>
In-reply-to
Content
> AFAIK the reason command history works in cmd.py on Windows is 
> that it's built into the terminal program. Or maybe into the
> operating system.

As mentioned in msg406800, input editing, history (e.g. up/down arrows, F7 popup, F8 completion), and alias support is implemented by the Windows console host (conhost.exe or openconsole.exe) for ReadFile() and ReadConsole() calls when the input stream is in line-input mode. Currently, it's the same whether a classic console session or a pseudoconsole (headless) session is hosted. When Windows Terminal is used, the overall connection of components looks like Python<->ConDrv (kernel device)<->OpenConsole<->NamedPipe (kernel device)<->Windows Terminal. The headless console's use of Windows Terminal for the user interface doesn't matter to Python's ReadConsoleW() call.

A headless console session always starts with 4 history buffers (one for each attached process) that store up to 50 commands. For a classic console session, the initial number and size of history buffers can be configured in the session properties or defaults. It can always be set dynamically via SetConsoleHistoryInfo(). There's *undocumented* support to get the commands from a history buffer that's associated with the name of an attached process: GetConsoleCommandHistoryLengthW(executable_name) and GetConsoleCommandHistoryW(buffer, buffer_length, executable_name). However, the API provides no function to set the command history. I suppose one could loop over WriteConsoleInputW() and ReadConsoleW() to implement it as a kludge.
History
Date User Action Args
2021-11-27 23:04:59eryksunsetrecipients: + eryksun, gvanrossum, rhettinger, terry.reedy, steve.dower, keeely
2021-11-27 23:04:59eryksunsetmessageid: <1638054299.82.0.48791171787.issue45870@roundup.psfhosted.org>
2021-11-27 23:04:59eryksunlinkissue45870 messages
2021-11-27 23:04:59eryksuncreate