27 #if defined(_MSC_VER) && _MSC_VER < 1600
33 #ifndef COMMON_LVB_REVERSE_VIDEO
34 # define COMMON_LVB_REVERSE_VIDEO 0x4000
44 # define InterlockedOr _InterlockedOr
47 #define UNICODE_REPLACEMENT_CHARACTER (0xfffd)
49 #define ANSI_NORMAL 0x0000
50 #define ANSI_ESCAPE_SEEN 0x0002
51 #define ANSI_CSI 0x0004
52 #define ANSI_ST_CONTROL 0x0008
53 #define ANSI_IGNORE 0x0010
54 #define ANSI_IN_ARG 0x0020
55 #define ANSI_IN_STRING 0x0040
56 #define ANSI_BACKSLASH_SEEN 0x0080
57 #define ANSI_EXTENSION 0x0100
58 #define ANSI_DECSCUSR 0x0200
60 #define MAX_INPUT_BUFFER_LENGTH 8192
61 #define MAX_CONSOLE_CHAR 8192
63 #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
64 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
67 #define CURSOR_SIZE_SMALL 25
68 #define CURSOR_SIZE_LARGE 100
71 CONSOLE_SCREEN_BUFFER_INFO* screen_buffer_info,
72 CONSOLE_CURSOR_INFO* cursor_info);
140 DWORD dwmsEventTime);
151 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
170 GENERIC_READ | GENERIC_WRITE,
177 CONSOLE_SCREEN_BUFFER_INFO sb_info;
180 WT_EXECUTELONGFUNCTION);
192 DWORD NumberOfEvents;
194 CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
195 CONSOLE_CURSOR_INFO cursor_info;
216 DUPLICATE_SAME_ACCESS))
221 readable = GetNumberOfConsoleInputEvents(
handle, &NumberOfEvents);
224 if (!GetConsoleScreenBufferInfo(
handle, &screen_buffer_info)) {
229 if (!GetConsoleCursorInfo(
handle, &cursor_info)) {
254 tty->reqs_pending = 0;
263 tty->tty.rd.read_raw_wait =
NULL;
266 tty->tty.rd.last_key_len = 0;
267 tty->tty.rd.last_key_offset = 0;
268 tty->tty.rd.last_utf16_high_surrogate = 0;
269 memset(&
tty->tty.rd.last_input_record, 0,
sizeof tty->tty.rd.last_input_record);
275 tty->tty.wr.utf8_bytes_left = 0;
276 tty->tty.wr.utf8_codepoint = 0;
279 tty->tty.wr.previous_eol = 0;
293 CONSOLE_SCREEN_BUFFER_INFO* screen_buffer_info,
294 CONSOLE_CURSOR_INFO* cursor_info) {
295 static int style_captured = 0;
352 unsigned char was_reading;
367 flags = ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
370 flags = ENABLE_WINDOW_INPUT;
381 alloc_cb =
tty->alloc_cb;
382 read_cb =
tty->read_cb;
394 if (!SetConsoleMode(
tty->handle,
flags)) {
418 CONSOLE_SCREEN_BUFFER_INFO
info;
420 if (!GetConsoleScreenBufferInfo(
tty->handle, &
info)) {
447 UnregisterWait(
handle->tty.rd.read_raw_wait);
467 memset(&
req->u.io.overlapped, 0,
sizeof(
req->u.io.overlapped));
469 r = RegisterWaitForSingleObject(&
handle->tty.rd.read_raw_wait,
474 WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE);
492 DWORD chars, read_chars;
495 BOOL read_console_success;
521 req->u.io.overlapped.InternalHigh = 0;
526 read_console_success = ReadConsoleW(
handle->handle,
532 if (read_console_success) {
533 read_bytes = WideCharToMultiByte(CP_UTF8,
537 handle->tty.rd.read_line_buffer.base,
542 req->u.io.overlapped.InternalHigh = read_bytes;
553 HANDLE active_screen_buffer;
554 active_screen_buffer = CreateFileA(
"conout$",
555 GENERIC_READ | GENERIC_WRITE,
556 FILE_SHARE_READ | FILE_SHARE_WRITE,
559 FILE_ATTRIBUTE_NORMAL,
571 SetConsoleCursorPosition(active_screen_buffer,
pos);
572 CloseHandle(active_screen_buffer);
591 memset(&
req->u.io.overlapped, 0,
sizeof(
req->u.io.overlapped));
595 if (
handle->tty.rd.read_line_buffer.base ==
NULL ||
596 handle->tty.rd.read_line_buffer.len == 0) {
599 &
handle->tty.rd.read_line_buffer);
611 WT_EXECUTELONGFUNCTION);
633 #define VK_CASE(vk, normal_str, shift_str, ctrl_str, shift_ctrl_str) \
635 if (shift && ctrl) { \
636 *len = sizeof shift_ctrl_str; \
637 return "\033" shift_ctrl_str; \
638 } else if (shift) { \
639 *len = sizeof shift_str ; \
640 return "\033" shift_str; \
642 *len = sizeof ctrl_str; \
643 return "\033" ctrl_str; \
645 *len = sizeof normal_str; \
646 return "\033" normal_str; \
654 VK_CASE(VK_INSERT,
"[2~",
"[2;2~",
"[2;5~",
"[2;6~")
655 VK_CASE(VK_END,
"[4~",
"[4;2~",
"[4;5~",
"[4;6~")
656 VK_CASE(VK_DOWN,
"[B",
"[1;2B",
"[1;5B",
"[1;6B")
657 VK_CASE(VK_NEXT,
"[6~",
"[6;2~",
"[6;5~",
"[6;6~")
658 VK_CASE(VK_LEFT,
"[D",
"[1;2D",
"[1;5D",
"[1;6D")
659 VK_CASE(VK_CLEAR,
"[G",
"[1;2G",
"[1;5G",
"[1;6G")
660 VK_CASE(VK_RIGHT,
"[C",
"[1;2C",
"[1;5C",
"[1;6C")
661 VK_CASE(VK_UP,
"[A",
"[1;2A",
"[1;5A",
"[1;6A")
662 VK_CASE(VK_HOME,
"[1~",
"[1;2~",
"[1;5~",
"[1;6~")
663 VK_CASE(VK_PRIOR,
"[5~",
"[5;2~",
"[5;5~",
"[5;6~")
664 VK_CASE(VK_DELETE,
"[3~",
"[3;2~",
"[3;5~",
"[3;6~")
665 VK_CASE(VK_NUMPAD0,
"[2~",
"[2;2~",
"[2;5~",
"[2;6~")
666 VK_CASE(VK_NUMPAD1,
"[4~",
"[4;2~",
"[4;5~",
"[4;6~")
667 VK_CASE(VK_NUMPAD2,
"[B",
"[1;2B",
"[1;5B",
"[1;6B")
668 VK_CASE(VK_NUMPAD3,
"[6~",
"[6;2~",
"[6;5~",
"[6;6~")
669 VK_CASE(VK_NUMPAD4,
"[D",
"[1;2D",
"[1;5D",
"[1;6D")
670 VK_CASE(VK_NUMPAD5,
"[G",
"[1;2G",
"[1;5G",
"[1;6G")
671 VK_CASE(VK_NUMPAD6,
"[C",
"[1;2C",
"[1;5C",
"[1;6C")
672 VK_CASE(VK_NUMPAD7,
"[A",
"[1;2A",
"[1;5A",
"[1;6A")
673 VK_CASE(VK_NUMPAD8,
"[1~",
"[1;2~",
"[1;5~",
"[1;6~")
674 VK_CASE(VK_NUMPAD9,
"[5~",
"[5;2~",
"[5;5~",
"[5;6~")
675 VK_CASE(VK_DECIMAL,
"[3~",
"[3;2~",
"[3;5~",
"[3;6~")
676 VK_CASE(VK_F1,
"[[A",
"[23~",
"[11^",
"[23^" )
677 VK_CASE(VK_F2,
"[[B",
"[24~",
"[12^",
"[24^" )
678 VK_CASE(VK_F3,
"[[C",
"[25~",
"[13^",
"[25^" )
679 VK_CASE(VK_F4,
"[[D",
"[26~",
"[14^",
"[26^" )
680 VK_CASE(VK_F5,
"[[E",
"[28~",
"[15^",
"[28^" )
681 VK_CASE(VK_F6,
"[17~",
"[29~",
"[17^",
"[29^" )
682 VK_CASE(VK_F7,
"[18~",
"[31~",
"[18^",
"[31^" )
683 VK_CASE(VK_F8,
"[19~",
"[32~",
"[19^",
"[32^" )
684 VK_CASE(VK_F9,
"[20~",
"[33~",
"[20^",
"[33^" )
685 VK_CASE(VK_F10,
"[21~",
"[34~",
"[21^",
"[34^" )
686 VK_CASE(VK_F11,
"[23~",
"[23$",
"[23^",
"[23@" )
687 VK_CASE(VK_F12,
"[24~",
"[24$",
"[24^",
"[24@" )
700 #define KEV handle->tty.rd.last_input_record.Event.KeyEvent
702 DWORD records_left, records_read;
727 if (!GetNumberOfConsoleInputEvents(
handle->handle, &records_left)) {
741 while ((records_left > 0 ||
handle->tty.rd.last_key_len > 0) &&
743 if (
handle->tty.rd.last_key_len == 0) {
745 if (!ReadConsoleInputW(
handle->handle,
746 &
handle->tty.rd.last_input_record,
760 if (
handle->tty.rd.last_input_record.EventType == WINDOW_BUFFER_SIZE_EVENT) {
765 if (
handle->tty.rd.last_input_record.EventType != KEY_EVENT) {
772 (
KEV.wVirtualKeyCode != VK_MENU ||
773 KEV.uChar.UnicodeChar == 0)) {
780 if ((
KEV.dwControlKeyState & LEFT_ALT_PRESSED) &&
781 !(
KEV.dwControlKeyState & ENHANCED_KEY) &&
782 (
KEV.wVirtualKeyCode == VK_INSERT ||
783 KEV.wVirtualKeyCode == VK_END ||
784 KEV.wVirtualKeyCode == VK_DOWN ||
785 KEV.wVirtualKeyCode == VK_NEXT ||
786 KEV.wVirtualKeyCode == VK_LEFT ||
787 KEV.wVirtualKeyCode == VK_CLEAR ||
788 KEV.wVirtualKeyCode == VK_RIGHT ||
789 KEV.wVirtualKeyCode == VK_HOME ||
790 KEV.wVirtualKeyCode == VK_UP ||
791 KEV.wVirtualKeyCode == VK_PRIOR ||
792 KEV.wVirtualKeyCode == VK_NUMPAD0 ||
793 KEV.wVirtualKeyCode == VK_NUMPAD1 ||
794 KEV.wVirtualKeyCode == VK_NUMPAD2 ||
795 KEV.wVirtualKeyCode == VK_NUMPAD3 ||
796 KEV.wVirtualKeyCode == VK_NUMPAD4 ||
797 KEV.wVirtualKeyCode == VK_NUMPAD5 ||
798 KEV.wVirtualKeyCode == VK_NUMPAD6 ||
799 KEV.wVirtualKeyCode == VK_NUMPAD7 ||
800 KEV.wVirtualKeyCode == VK_NUMPAD8 ||
801 KEV.wVirtualKeyCode == VK_NUMPAD9)) {
805 if (
KEV.uChar.UnicodeChar != 0) {
806 int prefix_len, char_len;
809 if (
KEV.uChar.UnicodeChar >= 0xD800 &&
810 KEV.uChar.UnicodeChar < 0xDC00) {
812 handle->tty.rd.last_utf16_high_surrogate =
KEV.uChar.UnicodeChar;
818 if ((
KEV.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
819 && !(
KEV.dwControlKeyState & (LEFT_CTRL_PRESSED |
820 RIGHT_CTRL_PRESSED)) &&
KEV.bKeyDown) {
821 handle->tty.rd.last_key[0] =
'\033';
827 if (
KEV.uChar.UnicodeChar >= 0xDC00 &&
828 KEV.uChar.UnicodeChar < 0xE000) {
830 WCHAR utf16_buffer[2];
831 utf16_buffer[0] =
handle->tty.rd.last_utf16_high_surrogate;
832 utf16_buffer[1] =
KEV.uChar.UnicodeChar;
833 char_len = WideCharToMultiByte(CP_UTF8,
837 &
handle->tty.rd.last_key[prefix_len],
838 sizeof handle->tty.rd.last_key,
843 char_len = WideCharToMultiByte(CP_UTF8,
845 &
KEV.uChar.UnicodeChar,
847 &
handle->tty.rd.last_key[prefix_len],
848 sizeof handle->tty.rd.last_key,
854 handle->tty.rd.last_utf16_high_surrogate = 0;
867 handle->tty.rd.last_key_len = (
unsigned char) (prefix_len + char_len);
868 handle->tty.rd.last_key_offset = 0;
874 size_t prefix_len, vt100_len;
877 !!(
KEV.dwControlKeyState & SHIFT_PRESSED),
878 !!(
KEV.dwControlKeyState & (
880 RIGHT_CTRL_PRESSED)),
889 if (
KEV.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) {
890 handle->tty.rd.last_key[0] =
'\033';
897 assert(prefix_len + vt100_len < sizeof handle->
tty.rd.last_key);
898 memcpy(&
handle->tty.rd.last_key[prefix_len], vt100, vt100_len);
900 handle->tty.rd.last_key_len = (
unsigned char) (prefix_len + vt100_len);
901 handle->tty.rd.last_key_offset = 0;
906 if (
handle->tty.rd.last_key_offset <
handle->tty.rd.last_key_len) {
918 buf.base[buf_used++] =
handle->tty.rd.last_key[
handle->tty.rd.last_key_offset++];
921 if ((
size_t) buf_used ==
buf.len) {
931 if (--
KEV.wRepeatCount > 0) {
932 handle->tty.rd.last_key_offset = 0;
936 handle->tty.rd.last_key_len = 0;
984 req->u.io.overlapped.InternalHigh != 0) {
1010 if (
handle->tty.rd.read_line_buffer.len == 0) {
1023 return ERROR_INVALID_PARAMETER;
1028 handle->read_cb = read_cb;
1029 handle->alloc_cb = alloc_cb;
1039 if (
handle->tty.rd.last_key_len > 0) {
1068 record.EventType = FOCUS_EVENT;
1069 if (!WriteConsoleInputW(
handle->handle, &
record, 1, &written)) {
1070 return GetLastError();
1107 active_screen_buffer = CreateFileA(
"conout$",
1108 GENERIC_READ | GENERIC_WRITE,
1109 FILE_SHARE_READ | FILE_SHARE_WRITE,
1112 FILE_ATTRIBUTE_NORMAL,
1116 GetConsoleScreenBufferInfo(active_screen_buffer,
1122 record.EventType = KEY_EVENT;
1124 record.Event.KeyEvent.wRepeatCount = 1;
1125 record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
1126 record.Event.KeyEvent.wVirtualScanCode =
1127 MapVirtualKeyW(VK_RETURN, MAPVK_VK_TO_VSC);
1128 record.Event.KeyEvent.uChar.UnicodeChar =
L'\r';
1129 record.Event.KeyEvent.dwControlKeyState = 0;
1130 if (!WriteConsoleInputW(
handle->handle, &
record, 1, &written))
1131 err = GetLastError();
1134 CloseHandle(active_screen_buffer);
1147 }
else if (uv_tty_virtual_offset < info->dwCursorPosition.Y -
1164 CONSOLE_SCREEN_BUFFER_INFO*
info,
int x,
unsigned char x_relative,
int y,
1165 unsigned char y_relative) {
1172 y =
info->dwCursorPosition.Y + y;
1185 x =
info->dwCursorPosition.X +
x;
1194 result.X = (
unsigned short)
x;
1195 result.Y = (
unsigned short) y;
1204 if (*
error != ERROR_SUCCESS) {
1208 if (!WriteConsoleW(
handle->handle,
1213 *
error = GetLastError();
1222 int y,
unsigned char y_relative,
DWORD*
error) {
1223 CONSOLE_SCREEN_BUFFER_INFO
info;
1226 if (*
error != ERROR_SUCCESS) {
1231 if (!GetConsoleScreenBufferInfo(
handle->handle, &
info)) {
1232 *
error = GetLastError();
1237 if (!SetConsoleCursorPosition(
handle->handle,
pos)) {
1238 if (GetLastError() == ERROR_INVALID_PARAMETER) {
1242 *
error = GetLastError();
1252 const COORD
origin = {0, 0};
1254 CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
1257 if (*
error != ERROR_SUCCESS) {
1262 if (!SetConsoleTextAttribute(
handle->handle, char_attrs)) {
1263 *
error = GetLastError();
1268 if (!SetConsoleCursorPosition(
handle->handle,
origin)) {
1269 *
error = GetLastError();
1275 if (!GetConsoleScreenBufferInfo(
handle->handle, &screen_buffer_info)) {
1276 *
error = GetLastError();
1280 count = screen_buffer_info.dwSize.X * screen_buffer_info.dwSize.Y;
1282 if (!(FillConsoleOutputCharacterW(
handle->handle,
1287 FillConsoleOutputAttribute(
handle->handle,
1292 if (GetLastError() == ERROR_INVALID_PARAMETER) {
1296 *
error = GetLastError();
1307 *
error = GetLastError();
1317 CONSOLE_SCREEN_BUFFER_INFO
info;
1322 int x1r, x2r, y1r, y2r;
1324 if (*
error != ERROR_SUCCESS) {
1349 if (!entire_screen) {
1362 if (!GetConsoleScreenBufferInfo(
handle->handle, &
info)) {
1363 *
error = GetLastError();
1372 if (!(FillConsoleOutputCharacterW(
handle->handle,
1377 FillConsoleOutputAttribute(
handle->handle,
1382 if (GetLastError() == ERROR_INVALID_PARAMETER) {
1386 *
error = GetLastError();
1396 WORD fg = info.wAttributes & 0xF; \
1397 WORD bg = info.wAttributes & 0xF0; \
1398 info.wAttributes &= 0xFF00; \
1399 info.wAttributes |= fg << 4; \
1400 info.wAttributes |= bg >> 4; \
1404 unsigned short argc =
handle->tty.wr.ansi_csi_argc;
1405 unsigned short*
argv =
handle->tty.wr.ansi_csi_argv;
1407 CONSOLE_SCREEN_BUFFER_INFO
info;
1409 char fg_color = -1, bg_color = -1;
1410 char fg_bright = -1, bg_bright = -1;
1422 for (
i = 0;
i < argc;
i++) {
1433 }
else if (
arg == 1) {
1437 }
else if (
arg == 2) {
1442 }
else if (
arg == 5) {
1446 }
else if (
arg == 7) {
1450 }
else if (
arg == 21 ||
arg == 22) {
1454 }
else if (
arg == 25) {
1458 }
else if (
arg == 27) {
1462 }
else if (
arg >= 30 &&
arg <= 37) {
1464 fg_color =
arg - 30;
1466 }
else if (
arg == 39) {
1471 }
else if (
arg >= 40 &&
arg <= 47) {
1473 bg_color =
arg - 40;
1475 }
else if (
arg == 49) {
1480 }
else if (
arg >= 90 &&
arg <= 97) {
1483 fg_color =
arg - 90;
1485 }
else if (
arg >= 100 &&
arg <= 107) {
1488 bg_color =
arg - 100;
1493 if (fg_color == -1 && bg_color == -1 && fg_bright == -1 &&
1494 bg_bright == -1 && inverse == -1) {
1499 if (!GetConsoleScreenBufferInfo(
handle->handle, &
info)) {
1500 *
error = GetLastError();
1508 if (fg_color != -1) {
1509 info.wAttributes &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
1510 if (fg_color & 1)
info.wAttributes |= FOREGROUND_RED;
1511 if (fg_color & 2)
info.wAttributes |= FOREGROUND_GREEN;
1512 if (fg_color & 4)
info.wAttributes |= FOREGROUND_BLUE;
1515 if (fg_bright != -1) {
1517 info.wAttributes |= FOREGROUND_INTENSITY;
1519 info.wAttributes &= ~FOREGROUND_INTENSITY;
1523 if (bg_color != -1) {
1524 info.wAttributes &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
1525 if (bg_color & 1)
info.wAttributes |= BACKGROUND_RED;
1526 if (bg_color & 2)
info.wAttributes |= BACKGROUND_GREEN;
1527 if (bg_color & 4)
info.wAttributes |= BACKGROUND_BLUE;
1530 if (bg_bright != -1) {
1532 info.wAttributes |= BACKGROUND_INTENSITY;
1534 info.wAttributes &= ~BACKGROUND_INTENSITY;
1538 if (inverse != -1) {
1550 if (!SetConsoleTextAttribute(
handle->handle,
info.wAttributes)) {
1551 *
error = GetLastError();
1561 CONSOLE_SCREEN_BUFFER_INFO
info;
1563 if (*
error != ERROR_SUCCESS) {
1567 if (!GetConsoleScreenBufferInfo(
handle->handle, &
info)) {
1568 *
error = GetLastError();
1574 handle->tty.wr.saved_position.X =
info.dwCursorPosition.X;
1578 if (save_attributes) {
1579 handle->tty.wr.saved_attributes =
info.wAttributes &
1580 (FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
1589 unsigned char restore_attributes,
DWORD*
error) {
1590 CONSOLE_SCREEN_BUFFER_INFO
info;
1591 WORD new_attributes;
1593 if (*
error != ERROR_SUCCESS) {
1599 handle->tty.wr.saved_position.X,
1601 handle->tty.wr.saved_position.Y,
1608 if (restore_attributes &&
1610 if (!GetConsoleScreenBufferInfo(
handle->handle, &
info)) {
1611 *
error = GetLastError();
1615 new_attributes =
info.wAttributes;
1616 new_attributes &= ~(FOREGROUND_INTENSITY | BACKGROUND_INTENSITY);
1617 new_attributes |=
handle->tty.wr.saved_attributes;
1619 if (!SetConsoleTextAttribute(
handle->handle, new_attributes)) {
1620 *
error = GetLastError();
1631 CONSOLE_CURSOR_INFO cursor_info;
1633 if (!GetConsoleCursorInfo(
handle->handle, &cursor_info)) {
1634 *
error = GetLastError();
1638 cursor_info.bVisible = visible;
1640 if (!SetConsoleCursorInfo(
handle->handle, &cursor_info)) {
1641 *
error = GetLastError();
1649 CONSOLE_CURSOR_INFO cursor_info;
1651 if (!GetConsoleCursorInfo(
handle->handle, &cursor_info)) {
1652 *
error = GetLastError();
1658 }
else if (style <= 2) {
1664 if (!SetConsoleCursorInfo(
handle->handle, &cursor_info)) {
1665 *
error = GetLastError();
1680 DWORD utf16_buf_used = 0;
1683 #define FLUSH_TEXT() \
1685 if (utf16_buf_used > 0) { \
1686 uv_tty_emit_text(handle, utf16_buf, utf16_buf_used, error); \
1687 utf16_buf_used = 0; \
1691 #define ENSURE_BUFFER_SPACE(wchars_needed) \
1692 if (wchars_needed > ARRAY_SIZE(utf16_buf) - utf16_buf_used) { \
1697 unsigned char utf8_bytes_left =
handle->tty.wr.utf8_bytes_left;
1698 unsigned int utf8_codepoint =
handle->tty.wr.utf8_codepoint;
1699 unsigned char previous_eol =
handle->tty.wr.previous_eol;
1700 unsigned short ansi_parser_state =
handle->tty.wr.ansi_parser_state;
1704 *
error = ERROR_SUCCESS;
1708 for (
i = 0;
i < nbufs;
i++) {
1712 for (j = 0; j <
buf.len; j++) {
1713 unsigned char c =
buf.base[j];
1718 if (utf8_bytes_left == 0) {
1720 DWORD first_zero_bit;
1721 unsigned char not_c = ~
c;
1723 if (_BitScanReverse(&first_zero_bit, not_c)) {
1726 first_zero_bit = (
sizeof(
int) * 8) - 1 - __builtin_clz(not_c);
1728 if (first_zero_bit == 7) {
1730 utf8_codepoint = (
unsigned int)
c;
1732 }
else if (first_zero_bit <= 5) {
1734 utf8_codepoint = (0xff >> (8 - first_zero_bit)) &
c;
1735 utf8_bytes_left = (char) (6 - first_zero_bit);
1747 }
else if ((
c & 0xc0) == 0x80) {
1750 utf8_codepoint <<= 6;
1751 utf8_codepoint |= ((
unsigned int)
c & 0x3f);
1755 utf8_bytes_left = 0;
1763 if (utf8_bytes_left != 0) {
1771 switch (utf8_codepoint) {
1778 handle->tty.wr.ansi_csi_argc = 0;
1783 switch (utf8_codepoint) {
1786 handle->tty.wr.ansi_csi_argc = 0;
1824 if (utf8_codepoint >=
'@' && utf8_codepoint <=
'_') {
1836 if (utf8_codepoint >=
'@' && utf8_codepoint <=
'~') {
1844 if (utf8_codepoint >=
'@' && utf8_codepoint <=
'~') {
1846 if (utf8_codepoint ==
'q') {
1848 int style =
handle->tty.wr.ansi_csi_argc
1849 ?
handle->tty.wr.ansi_csi_argv[0] : 1;
1850 if (style >= 0 && style <= 6) {
1864 }
else if (ansi_parser_state &
ANSI_CSI) {
1868 if (utf8_codepoint >=
'0' && utf8_codepoint <=
'9') {
1873 if (
handle->tty.wr.ansi_csi_argc >=
1879 handle->tty.wr.ansi_csi_argc++;
1880 handle->tty.wr.ansi_csi_argv[
handle->tty.wr.ansi_csi_argc - 1] =
1881 (
unsigned short) utf8_codepoint -
'0';
1887 handle->tty.wr.ansi_csi_argv[
handle->tty.wr.ansi_csi_argc - 1];
1895 handle->tty.wr.ansi_csi_argv[
handle->tty.wr.ansi_csi_argc - 1] =
1896 (
unsigned short)
value + (utf8_codepoint -
'0');
1900 }
else if (utf8_codepoint ==
';') {
1911 if (
handle->tty.wr.ansi_csi_argc >=
1918 handle->tty.wr.ansi_csi_argc++;
1919 handle->tty.wr.ansi_csi_argv[
handle->tty.wr.ansi_csi_argc - 1] = 0;
1923 }
else if (utf8_codepoint ==
'?' &&
1926 handle->tty.wr.ansi_csi_argc == 0) {
1933 }
else if (utf8_codepoint ==
' ' &&
1940 }
else if (utf8_codepoint >=
'@' && utf8_codepoint <=
'~') {
1944 switch (utf8_codepoint) {
1947 if (
handle->tty.wr.ansi_csi_argc == 1 &&
1948 handle->tty.wr.ansi_csi_argv[0] == 25) {
1956 if (
handle->tty.wr.ansi_csi_argc == 1 &&
1957 handle->tty.wr.ansi_csi_argv[0] == 25) {
1967 switch (utf8_codepoint) {
1971 y = -(
handle->tty.wr.ansi_csi_argc
1972 ?
handle->tty.wr.ansi_csi_argv[0] : 1);
1979 y =
handle->tty.wr.ansi_csi_argc
1980 ?
handle->tty.wr.ansi_csi_argv[0] : 1;
1987 x =
handle->tty.wr.ansi_csi_argc
1988 ?
handle->tty.wr.ansi_csi_argv[0] : 1;
1995 x = -(
handle->tty.wr.ansi_csi_argc
1996 ?
handle->tty.wr.ansi_csi_argv[0] : 1);
2003 y =
handle->tty.wr.ansi_csi_argc
2004 ?
handle->tty.wr.ansi_csi_argv[0] : 1;
2011 y = -(
handle->tty.wr.ansi_csi_argc
2012 ?
handle->tty.wr.ansi_csi_argv[0] : 1);
2019 x = (
handle->tty.wr.ansi_csi_argc >= 1 &&
2020 handle->tty.wr.ansi_csi_argv[0])
2021 ?
handle->tty.wr.ansi_csi_argv[0] - 1 : 0;
2029 y = (
handle->tty.wr.ansi_csi_argc >= 1 &&
2030 handle->tty.wr.ansi_csi_argv[0])
2031 ?
handle->tty.wr.ansi_csi_argv[0] - 1 : 0;
2032 x = (
handle->tty.wr.ansi_csi_argc >= 2 &&
2033 handle->tty.wr.ansi_csi_argv[1])
2034 ?
handle->tty.wr.ansi_csi_argv[1] - 1 : 0;
2041 d =
handle->tty.wr.ansi_csi_argc
2042 ?
handle->tty.wr.ansi_csi_argv[0] : 0;
2043 if (
d >= 0 &&
d <= 2) {
2051 d =
handle->tty.wr.ansi_csi_argc
2052 ?
handle->tty.wr.ansi_csi_argv[0] : 0;
2053 if (
d >= 0 &&
d <= 2) {
2094 if (utf8_codepoint ==
'"') {
2096 }
else if (utf8_codepoint ==
'\\') {
2103 if (utf8_codepoint ==
'\007' || (utf8_codepoint ==
'\\' &&
2107 }
else if (utf8_codepoint ==
'\033') {
2110 }
else if (utf8_codepoint ==
'"') {
2125 if (utf8_codepoint == 0x0a || utf8_codepoint == 0x0d) {
2128 if (utf8_codepoint == 0x0a && previous_eol != 0x0d) {
2131 utf16_buf[utf16_buf_used++] =
L'\r';
2132 utf16_buf[utf16_buf_used++] =
L'\n';
2133 }
else if (utf8_codepoint == 0x0d && previous_eol == 0x0a) {
2141 utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint;
2144 previous_eol = (char) utf8_codepoint;
2146 }
else if (utf8_codepoint <= 0xffff) {
2149 utf16_buf[utf16_buf_used++] = (WCHAR) utf8_codepoint;
2153 utf8_codepoint -= 0x10000;
2154 utf16_buf[utf16_buf_used++] = (WCHAR) (utf8_codepoint / 0x400 + 0xD800);
2155 utf16_buf[utf16_buf_used++] = (WCHAR) (utf8_codepoint % 0x400 + 0xDC00);
2165 handle->tty.wr.utf8_bytes_left = utf8_bytes_left;
2166 handle->tty.wr.utf8_codepoint = utf8_codepoint;
2167 handle->tty.wr.previous_eol = previous_eol;
2168 handle->tty.wr.ansi_parser_state = ansi_parser_state;
2195 handle->stream.conn.write_reqs_pending++;
2198 req->u.io.queued_bytes = 0;
2214 unsigned int nbufs) {
2217 if (
handle->stream.conn.write_reqs_pending > 0)
2231 handle->write_queue_size -=
req->u.io.queued_bytes;
2239 handle->stream.conn.write_reqs_pending--;
2240 if (
handle->stream.conn.shutdown_req !=
NULL &&
2241 handle->stream.conn.write_reqs_pending == 0) {
2255 CloseHandle(
handle->handle);
2264 if (
handle->reqs_pending == 0) {
2273 handle->stream.conn.write_reqs_pending == 0) {
2277 if (
handle->stream.conn.shutdown_req->cb) {
2279 handle->stream.conn.shutdown_req->cb(
handle->stream.conn.shutdown_req, UV_ECANCELED);
2281 handle->stream.conn.shutdown_req->cb(
handle->stream.conn.shutdown_req, 0);
2292 handle->reqs_pending == 0) {
2337 if (!GetConsoleMode(
handle, &dwMode)) {
2342 if (!SetConsoleMode(
handle, dwMode)) {
2351 ULONG_PTR conhost_pid;
2360 sizeof(conhost_pid),
2371 conhost_pid &= ~(ULONG_PTR)0x3;
2378 WT_EXECUTELONGFUNCTION) == 0)
2382 EVENT_CONSOLE_LAYOUT,
2387 WINEVENT_OUTOFCONTEXT))
2390 while (GetMessage(&
msg,
NULL, 0, 0)) {
2391 TranslateMessage(&
msg);
2392 DispatchMessage(&
msg);
2402 DWORD dwEventThread,
2403 DWORD dwmsEventTime) {
2419 CONSOLE_SCREEN_BUFFER_INFO sb_info;
2425 width = sb_info.dwSize.X;
2426 height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1;
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
static mcore_handle handle
RzBinInfo * info(RzBinFile *bf)
const lzma_allocator const uint8_t size_t uint8_t * out
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
#define DECREASE_ACTIVE_COUNT(loop, handle)
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
static INLINE HANDLE uv__get_osfhandle(int fd)
#define INCREASE_ACTIVE_COUNT(loop, handle)
#define uv__handle_close(handle)
#define DECREASE_PENDING_REQ_COUNT(handle)
#define uv__handle_closing(handle)
#define INVALID_HANDLE_VALUE
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char argv
static const char struct stat static buf struct stat static buf static vhangup int status
assert(limit<=UINT32_MAX/2)
#define GET_REQ_ERROR(req)
static INLINE void uv_insert_pending_req(uv_loop_t *loop, uv_req_t *req)
#define SET_REQ_SUCCESS(req)
#define UNREGISTER_HANDLE_REQ(loop, handle, req)
#define REGISTER_HANDLE_REQ(loop, handle, req)
#define POST_COMPLETION_FOR_REQ(loop, req)
#define SET_REQ_ERROR(req, error)
static struct sockaddr static addrlen static backlog const void static flags void flags
static struct sockaddr static addrlen static backlog const void msg
static INLINE void uv_stream_init(uv_loop_t *loop, uv_stream_t *handle, uv_handle_type type)
static INLINE void uv_connection_init(uv_stream_t *handle)
int uv__signal_dispatch(int signum)
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
void uv_tty_set_vterm_state(uv_tty_vtermstate_t state)
int uv_tty_get_winsize(uv_tty_t *tty, int *width, int *height)
int uv_tty_set_mode(uv_tty_t *tty, uv_tty_mode_t mode)
int uv_tty_get_vterm_state(uv_tty_vtermstate_t *state)
int uv_tty_init(uv_loop_t *loop, uv_tty_t *tty, int fd, int unused)
int uv_tty_reset_mode(void)
UV_PLATFORM_SEM_T uv_sem_t
pthread_mutex_t uv_mutex_t
void error(const char *msg)
size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs)
@ UV_HANDLE_TTY_SAVED_POSITION
@ UV_HANDLE_TTY_SAVED_ATTRIBUTES
@ UV_HANDLE_CANCELLATION_PENDING
#define UV_REQ_INIT(req, typ)
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
void(* uv_write_cb)(uv_write_t *req, int status)
UV_EXTERN int uv_translate_sys_error(int sys_errno)
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
UV_EXTERN void uv_sem_post(uv_sem_t *sem)
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
void(* uv_read_cb)(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
void(* uv_alloc_cb)(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
UV_EXTERN void uv_sem_wait(uv_sem_t *sem)
UV_EXTERN int uv_sem_init(uv_sem_t *sem, unsigned int value)
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
static int uv_tty_clear(uv_tty_t *handle, int dir, char entire_screen, DWORD *error)
static uv_sem_t uv_tty_output_lock
static int uv_tty_virtual_height
static void uv_tty_queue_read_line(uv_loop_t *loop, uv_tty_t *handle)
static void uv_tty_capture_initial_style(CONSOLE_SCREEN_BUFFER_INFO *screen_buffer_info, CONSOLE_CURSOR_INFO *cursor_info)
static char uv_tty_default_inverse
#define MAX_INPUT_BUFFER_LENGTH
#define CURSOR_SIZE_LARGE
static int uv_tty_set_style(uv_tty_t *handle, DWORD *error)
static char uv_tty_default_bg_color
static void uv_tty_queue_read(uv_loop_t *loop, uv_tty_t *handle)
static int uv_tty_save_state(uv_tty_t *handle, unsigned char save_attributes, DWORD *error)
static DWORD CALLBACK uv_tty_line_read_thread(void *data)
static int uv__tty_console_height
static void CALLBACK uv__tty_console_resize_event(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
static char uv_tty_default_bg_bright
static int uv_tty_write_bufs(uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs, DWORD *error)
int uv_tty_write(uv_loop_t *loop, uv_write_t *req, uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
#define VK_CASE(vk, normal_str, shift_str, ctrl_str, shift_ctrl_str)
static char uv_tty_default_fg_color
#define UNICODE_REPLACEMENT_CHARACTER
static uv_tty_vtermstate_t uv__vterm_state
static int uv_tty_virtual_width
static const char * get_vt100_fn_key(DWORD code, char shift, char ctrl, size_t *len)
int uv_tty_read_stop(uv_tty_t *handle)
static BOOL uv__need_check_vterm_state
static HANDLE uv__tty_console_resized
static int uv_tty_virtual_offset
static void uv__determine_vterm_state(HANDLE handle)
static void uv_tty_queue_read_raw(uv_loop_t *loop, uv_tty_t *handle)
#define ENSURE_BUFFER_SPACE(wchars_needed)
static int uv__tty_console_width
static CONSOLE_CURSOR_INFO uv_tty_default_cursor_info
void uv_tty_endgame(uv_loop_t *loop, uv_tty_t *handle)
static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO *info)
static uv_mutex_t uv__tty_console_resize_mutex
static int uv__cancel_read_console(uv_tty_t *handle)
static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void *param)
static int uv_tty_set_cursor_visibility(uv_tty_t *handle, BOOL visible, DWORD *error)
void uv_process_tty_write_req(uv_loop_t *loop, uv_tty_t *handle, uv_write_t *req)
static volatile LONG uv__restore_screen_state
static void uv__tty_console_signal_resize(void)
void uv_process_tty_connect_req(uv_loop_t *loop, uv_tty_t *handle, uv_connect_t *req)
void uv_process_tty_accept_req(uv_loop_t *loop, uv_tty_t *handle, uv_req_t *raw_req)
int uv__tty_try_write(uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
static CONSOLE_SCREEN_BUFFER_INFO uv__saved_screen_state
void uv_process_tty_read_line_req(uv_loop_t *loop, uv_tty_t *handle, uv_req_t *req)
static HANDLE uv__tty_console_handle
static int uv_tty_set_cursor_shape(uv_tty_t *handle, int style, DWORD *error)
static int uv_tty_reset(uv_tty_t *handle, DWORD *error)
static void CALLBACK uv_tty_post_raw_read(void *data, BOOLEAN didTimeout)
void uv_tty_close(uv_tty_t *handle)
static char uv_tty_default_fg_bright
void uv_process_tty_read_raw_req(uv_loop_t *loop, uv_tty_t *handle, uv_req_t *req)
int uv_tty_read_start(uv_tty_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
static int uv_tty_restore_state(uv_tty_t *handle, unsigned char restore_attributes, DWORD *error)
static int uv_tty_emit_text(uv_tty_t *handle, WCHAR buffer[], DWORD length, DWORD *error)
#define ANSI_BACKSLASH_SEEN
static volatile LONG uv__read_console_status
uv__read_console_status_e
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING
static WORD uv_tty_default_text_attributes
#define COMMON_LVB_REVERSE_VIDEO
static int uv_tty_move_caret(uv_tty_t *handle, int x, unsigned char x_relative, int y, unsigned char y_relative, DWORD *error)
void uv_console_init(void)
#define CURSOR_SIZE_SMALL
static DWORD WINAPI uv__tty_console_resize_watcher_thread(void *param)
static COORD uv_tty_make_real_coord(uv_tty_t *handle, CONSOLE_SCREEN_BUFFER_INFO *info, int x, unsigned char x_relative, int y, unsigned char y_relative)
static const uv_buf_t uv_null_buf_
void uv_process_tty_read_req(uv_loop_t *loop, uv_tty_t *handle, uv_req_t *req)
sNtQueryInformationProcess pNtQueryInformationProcess
sSetWinEventHook pSetWinEventHook
#define ProcessConsoleHostProcess
#define NT_SUCCESS(status)
static const z80_opcode fd[]