On Tue, Jun 17, 2025 at 12:18:07PM -0800, Junio C Hamano wrote: > "James Duley via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes: > > > This is because save_term doesn't set cmode_out when not DUPLEX, > > so an old version of cmode_out was being used. To fully address that bug though, something like the following (untested) needs to be squashed on top, right?: ---- diff --git a/compat/terminal.c b/compat/terminal.c index 72b184555f..8a197ffea1 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -279,7 +279,7 @@ void restore_term(void) SetConsoleMode(hconin, cmode_in); CloseHandle(hconin); - if (hconout != INVALID_HANDLE_VALUE) { + if (cmode_out && hconout != INVALID_HANDLE_VALUE) { SetConsoleMode(hconout, cmode_out); CloseHandle(hconout); } @@ -299,11 +299,15 @@ int save_term(enum save_term_flags flags) hconout = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hconout == INVALID_HANDLE_VALUE) + if (hconout == INVALID_HANDLE_VALUE) { + cmode_out = 0; goto error; + } GetConsoleMode(hconout, &cmode_out); } + else + cmode_out = 0; GetConsoleMode(hconin, &cmode_in); use_stty = 0; It would be nice to know, if the problem with vi that this was meant to address, and that needs further changes, that are only in the git for windows fork is stll relevant, so this could be cleaned further. Carlo