Screen clearing in CMD without "Legacy Console Mode"

Kevin Locke
Fri Apr 30 14:25:12 GMT 2021

Hi All,

I'm investigating an issue in Git for Windows[^1], which also affects
Cygwin.  The issue is that, when using CMD (i.e. Command Prompt) on
Windows 10 1703 or above with "Legacy Console Mode"[^2] disabled, if
TERM=cygwin is set in the environment, the console is not cleared when
vi exits.  To demonstrate, with Cygwin 3.2.0, in CMD with "Legacy
Console Mode" disabled:

cd C:\cygwin64
set TERM=cygwin
bin\vi etc\bash.bashrc

After exiting vi, the console window has not been cleared and content
from etc\bash.bashrc remains visible, making further use of the console
difficult until cleared.

The difference appears to result from enabling
SetConsoleMode(ENABLE_VIRTUAL_TERMINAL_INPUT)[^3] to behave like
xterm-256color when supported[^4] (they are not supported in "Legacy
Console Mode").

I'm not too familiar with TTY/PTY handling, much less Cygwin on top of
CMD.  It's not clear to me if the alternate screen buffer behaves
differently in CMD than xterm, whether Cygwin has any responsibility, or
if the issue is in how CMD handles ANSI escape sequences.  Johannes
Schindelin suggested it may make sense not to enable virtual terminal
processing when TERM=cygwin is set.[^5]  Thoughts?

Any advice or assistance for how to address this issue would be



More information about the Cygwin mailing list