Skip to content

Commit

Permalink
Windows: fix iread (#384)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adoxa committed Jun 16, 2023
1 parent e22f243 commit eebf1b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 11 additions & 4 deletions os.c
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions screen.c
Expand Up @@ -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
Expand Down

0 comments on commit eebf1b5

Please sign in to comment.