File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -578,6 +578,37 @@ void console_set_color(console_state & con_st, console_color_t color) {
578578}
579579
580580char32_t getchar32 () {
581+ #if defined(_WIN32)
582+ HANDLE hConsole = GetStdHandle (STD_INPUT_HANDLE);
583+ wchar_t high_surrogate = 0 ;
584+
585+ while (true ) {
586+ INPUT_RECORD record;
587+ DWORD count;
588+ if (!ReadConsoleInputW (hConsole, &record, 1 , &count) || count == 0 ) {
589+ return WEOF;
590+ }
591+
592+ if (record.EventType == KEY_EVENT && record.Event .KeyEvent .bKeyDown ) {
593+ wchar_t wc = record.Event .KeyEvent .uChar .UnicodeChar ;
594+ if (wc == 0 ) {
595+ continue ;
596+ }
597+
598+ if ((wc >= 0xD800 ) && (wc <= 0xDBFF )) { // Check if wc is a high surrogate
599+ high_surrogate = wc;
600+ continue ;
601+ } else if ((wc >= 0xDC00 ) && (wc <= 0xDFFF )) { // Check if wc is a low surrogate
602+ if (high_surrogate != 0 ) { // Check if we have a high surrogate
603+ return ((high_surrogate - 0xD800 ) << 10 ) + (wc - 0xDC00 ) + 0x10000 ;
604+ }
605+ }
606+
607+ high_surrogate = 0 ; // Reset the high surrogate
608+ return static_cast <char32_t >(wc);
609+ }
610+ }
611+ #else
581612 wchar_t wc = getwchar ();
582613 if (static_cast <wint_t >(wc) == WEOF) {
583614 return WEOF;
@@ -596,6 +627,7 @@ char32_t getchar32() {
596627#endif
597628
598629 return static_cast <char32_t >(wc);
630+ #endif
599631}
600632
601633void pop_cursor (console_state & con_st) {
You can’t perform that action at this time.
0 commit comments