From eebf1b55920cf72872f4c40dc144ecee7e1983b6 Mon Sep 17 00:00:00 2001 From: Jason Hood Date: Sat, 17 Jun 2023 01:46:56 +1000 Subject: [PATCH] Windows: fix iread (#384) The Windows version of iread removed the character, causing an extended sequence to be incorrectly split. Add an unget function to put the character back. Resolves #378. --- os.c | 15 +++++++++++---- screen.c | 10 ++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/os.c b/os.c index b9097c41..35eb1533 100644 --- a/os.c +++ b/os.c @@ -244,11 +244,18 @@ public int iread(int fd, unsigned char *buf, unsigned int len) } #else #if MSDOS_COMPILER==WIN32C - if (win32_kbhit() && WIN32getch() == intr_char) + if (win32_kbhit()) { - sigs |= S_INTERRUPT; - reading = 0; - return (READ_INTR); + int c; + + c = WIN32getch(); + if (c == intr_char) + { + sigs |= S_INTERRUPT; + reading = 0; + return (READ_INTR); + } + WIN32ungetch(c); } #endif #endif diff --git a/screen.c b/screen.c index 61931855..1acf8236 100644 --- a/screen.c +++ b/screen.c @@ -2956,6 +2956,16 @@ public char WIN32getch(void) return ascii; } + +/* + * Restore the character read during iread. + */ +public void WIN32ungetch(int ch) +{ + currentKey.unicode = ch; + ++keyCount; + pending_scancode = 0; +} #endif #if MSDOS_COMPILER