File tree 1 file changed +32
-0
lines changed
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) {
578
578
}
579
579
580
580
char32_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
581
612
wchar_t wc = getwchar ();
582
613
if (static_cast <wint_t >(wc) == WEOF) {
583
614
return WEOF;
@@ -596,6 +627,7 @@ char32_t getchar32() {
596
627
#endif
597
628
598
629
return static_cast <char32_t >(wc);
630
+ #endif
599
631
}
600
632
601
633
void pop_cursor (console_state & con_st) {
You can’t perform that action at this time.
0 commit comments