From f9b38a9f0c722ca269845da87a8d3fd2944150f6 Mon Sep 17 00:00:00 2001 From: James Duley Date: Tue, 17 Jun 2025 09:17:06 +1200 Subject: [PATCH] Ensure restore_term works correctly with DUPLEX Previously, if save_term/restore_term was called with the DUPLEX flag and then without the flag, an assertion was hit. > Assertion failed: hconout != INVALID_HANDLE_VALUE, > file compat/terminal.c, line 283 This is because save_term doesn't set cmode_out when not DUPLEX, so an old version of cmode_out was being used. Therefore, hconout is the correct thing for restore to check to decide whether to restore stdout console mode. I saw this on Windows with interactive.singleKey when doing `git add -p`. Specifically, after hitting `e` to edit in vim, once on to the prompt for the next hunk, pressing any key results in the assertion. Signed-off-by: James Duley --- compat/terminal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compat/terminal.c b/compat/terminal.c index 584f27bf7e1078..72b184555ff518 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -279,8 +279,7 @@ void restore_term(void) SetConsoleMode(hconin, cmode_in); CloseHandle(hconin); - if (cmode_out) { - assert(hconout != INVALID_HANDLE_VALUE); + if (hconout != INVALID_HANDLE_VALUE) { SetConsoleMode(hconout, cmode_out); CloseHandle(hconout); }