Lines Matching +full:continue +full:- +full:on +full:- +full:error
34 #include "handle-inl.h"
35 #include "stream-inl.h"
36 #include "req-inl.h"
102 * mean that it would extend beyond the bottom of the screen buffer - in that
109 * Since all tty i/o happens on the same console, this window is shared
113 static int uv_tty_virtual_offset = -1;
114 static int uv_tty_virtual_height = -1;
115 static int uv_tty_virtual_width = -1;
123 static int uv__tty_console_height = -1;
124 static int uv__tty_console_width = -1;
176 uv__tty_console_height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1; in uv__console_init()
199 /* In order to avoid closing a stdio file descriptor 0-2, duplicate the in uv_tty_init()
213 fd = -1; in uv_tty_init()
247 tty->handle = handle; in uv_tty_init()
248 tty->u.fd = fd; in uv_tty_init()
249 tty->reqs_pending = 0; in uv_tty_init()
250 tty->flags |= UV_HANDLE_BOUND; in uv_tty_init()
254 tty->flags |= UV_HANDLE_TTY_READABLE | UV_HANDLE_READABLE; in uv_tty_init()
256 tty->tty.rd.unused_ = NULL; in uv_tty_init()
257 tty->tty.rd.read_line_buffer = uv_null_buf_; in uv_tty_init()
258 tty->tty.rd.read_raw_wait = NULL; in uv_tty_init()
260 /* Init keycode-to-vt100 mapper state. */ in uv_tty_init()
261 tty->tty.rd.last_key_len = 0; in uv_tty_init()
262 tty->tty.rd.last_key_offset = 0; in uv_tty_init()
263 tty->tty.rd.last_utf16_high_surrogate = 0; in uv_tty_init()
264 memset(&tty->tty.rd.last_input_record, 0, sizeof tty->tty.rd.last_input_record); in uv_tty_init()
267 tty->flags |= UV_HANDLE_WRITABLE; in uv_tty_init()
269 /* Init utf8-to-utf16 conversion state. */ in uv_tty_init()
270 tty->tty.wr.utf8_bytes_left = 0; in uv_tty_init()
271 tty->tty.wr.utf8_codepoint = 0; in uv_tty_init()
274 tty->tty.wr.previous_eol = 0; in uv_tty_init()
277 tty->tty.wr.ansi_parser_state = ANSI_NORMAL; in uv_tty_init()
284 /* Set the default console text attributes based on how the console was
298 uv_tty_default_text_attributes = screen_buffer_info->wAttributes; in uv__tty_capture_initial_style()
300 /* Convert black text on black background to use white text. */ in uv__tty_capture_initial_style()
352 if (!(tty->flags & UV_HANDLE_TTY_READABLE)) { in uv_tty_set_mode()
356 if (!!mode == !!(tty->flags & UV_HANDLE_TTY_RAW)) { in uv_tty_set_mode()
374 if (tty->flags & UV_HANDLE_READING) { in uv_tty_set_mode()
376 alloc_cb = tty->alloc_cb; in uv_tty_set_mode()
377 read_cb = tty->read_cb; in uv_tty_set_mode()
389 if (!SetConsoleMode(tty->handle, flags)) { in uv_tty_set_mode()
397 tty->flags &= ~UV_HANDLE_TTY_RAW; in uv_tty_set_mode()
398 tty->flags |= mode ? UV_HANDLE_TTY_RAW : 0; in uv_tty_set_mode()
415 if (!GetConsoleScreenBufferInfo(tty->handle, &info)) { in uv_tty_get_winsize()
439 handle = (uv_tty_t*) req->data; in uv_tty_post_raw_read()
440 loop = handle->loop; in uv_tty_post_raw_read()
442 UnregisterWait(handle->tty.rd.read_raw_wait); in uv_tty_post_raw_read()
443 handle->tty.rd.read_raw_wait = NULL; in uv_tty_post_raw_read()
454 assert(handle->flags & UV_HANDLE_READING); in uv__tty_queue_read_raw()
455 assert(!(handle->flags & UV_HANDLE_READ_PENDING)); in uv__tty_queue_read_raw()
457 assert(handle->handle && handle->handle != INVALID_HANDLE_VALUE); in uv__tty_queue_read_raw()
459 handle->tty.rd.read_line_buffer = uv_null_buf_; in uv__tty_queue_read_raw()
461 req = &handle->read_req; in uv__tty_queue_read_raw()
462 memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped)); in uv__tty_queue_read_raw()
464 r = RegisterWaitForSingleObject(&handle->tty.rd.read_raw_wait, in uv__tty_queue_read_raw()
465 handle->handle, in uv__tty_queue_read_raw()
471 handle->tty.rd.read_raw_wait = NULL; in uv__tty_queue_read_raw()
476 handle->flags |= UV_HANDLE_READ_PENDING; in uv__tty_queue_read_raw()
477 handle->reqs_pending++; in uv__tty_queue_read_raw()
497 handle = (uv_tty_t*) req->data; in uv_tty_line_read_thread()
498 loop = handle->loop; in uv_tty_line_read_thread()
500 assert(handle->tty.rd.read_line_buffer.base != NULL); in uv_tty_line_read_thread()
501 assert(handle->tty.rd.read_line_buffer.len > 0); in uv_tty_line_read_thread()
504 if (handle->tty.rd.read_line_buffer.len < MAX_INPUT_BUFFER_LENGTH) { in uv_tty_line_read_thread()
505 bytes = handle->tty.rd.read_line_buffer.len; in uv_tty_line_read_thread()
510 /* At last, unicode! One utf-16 codeunit never takes more than 3 utf-8 in uv_tty_line_read_thread()
518 req->u.io.overlapped.InternalHigh = 0; in uv_tty_line_read_thread()
523 read_console_success = ReadConsoleW(handle->handle, in uv_tty_line_read_thread()
533 &handle->tty.rd.read_line_buffer.base, in uv_tty_line_read_thread()
536 req->u.io.overlapped.InternalHigh = (DWORD) read_bytes; in uv_tty_line_read_thread()
562 if (pos.Y == uv__saved_screen_state.dwSize.Y - 1) in uv_tty_line_read_thread()
563 pos.Y--; in uv_tty_line_read_thread()
580 assert(handle->flags & UV_HANDLE_READING); in uv__tty_queue_read_line()
581 assert(!(handle->flags & UV_HANDLE_READ_PENDING)); in uv__tty_queue_read_line()
582 assert(handle->handle && handle->handle != INVALID_HANDLE_VALUE); in uv__tty_queue_read_line()
584 req = &handle->read_req; in uv__tty_queue_read_line()
585 memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped)); in uv__tty_queue_read_line()
587 handle->tty.rd.read_line_buffer = uv_buf_init(NULL, 0); in uv__tty_queue_read_line()
588 handle->alloc_cb((uv_handle_t*) handle, 8192, &handle->tty.rd.read_line_buffer); in uv__tty_queue_read_line()
589 if (handle->tty.rd.read_line_buffer.base == NULL || in uv__tty_queue_read_line()
590 handle->tty.rd.read_line_buffer.len == 0) { in uv__tty_queue_read_line()
591 handle->read_cb((uv_stream_t*) handle, in uv__tty_queue_read_line()
593 &handle->tty.rd.read_line_buffer); in uv__tty_queue_read_line()
596 assert(handle->tty.rd.read_line_buffer.base != NULL); in uv__tty_queue_read_line()
599 in progress. We are also relying on the memory barrier provided by in uv__tty_queue_read_line()
611 handle->flags |= UV_HANDLE_READ_PENDING; in uv__tty_queue_read_line()
612 handle->reqs_pending++; in uv__tty_queue_read_line()
617 if (handle->flags & UV_HANDLE_TTY_RAW) { in uv__tty_queue_read()
644 /* These mappings are the same as Cygwin's. Unmodified and alt-modified in get_vt100_fn_key()
646 * modifier usage. F1. f12 and shift-f1. f10 comply with linux console, f6. in get_vt100_fn_key()
693 /* Shortcut for handle->tty.rd.last_input_record.Event.KeyEvent. */ in uv_process_tty_read_raw_req()
694 #define KEV handle->tty.rd.last_input_record.Event.KeyEvent in uv_process_tty_read_raw_req()
700 assert(handle->type == UV_TTY); in uv_process_tty_read_raw_req()
701 assert(handle->flags & UV_HANDLE_TTY_READABLE); in uv_process_tty_read_raw_req()
702 handle->flags &= ~UV_HANDLE_READ_PENDING; in uv_process_tty_read_raw_req()
704 if (!(handle->flags & UV_HANDLE_READING) || in uv_process_tty_read_raw_req()
705 !(handle->flags & UV_HANDLE_TTY_RAW)) { in uv_process_tty_read_raw_req()
710 /* An error occurred while waiting for the event. */ in uv_process_tty_read_raw_req()
711 if ((handle->flags & UV_HANDLE_READING)) { in uv_process_tty_read_raw_req()
712 handle->flags &= ~UV_HANDLE_READING; in uv_process_tty_read_raw_req()
713 handle->read_cb((uv_stream_t*)handle, in uv_process_tty_read_raw_req()
721 if (!GetNumberOfConsoleInputEvents(handle->handle, &records_left)) { in uv_process_tty_read_raw_req()
722 handle->flags &= ~UV_HANDLE_READING; in uv_process_tty_read_raw_req()
724 handle->read_cb((uv_stream_t*)handle, in uv_process_tty_read_raw_req()
731 * allocated on demand, when there's actually something to emit. */ in uv_process_tty_read_raw_req()
735 while ((records_left > 0 || handle->tty.rd.last_key_len > 0) && in uv_process_tty_read_raw_req()
736 (handle->flags & UV_HANDLE_READING)) { in uv_process_tty_read_raw_req()
737 if (handle->tty.rd.last_key_len == 0) { in uv_process_tty_read_raw_req()
739 if (!ReadConsoleInputW(handle->handle, in uv_process_tty_read_raw_req()
740 &handle->tty.rd.last_input_record, in uv_process_tty_read_raw_req()
743 handle->flags &= ~UV_HANDLE_READING; in uv_process_tty_read_raw_req()
745 handle->read_cb((uv_stream_t*) handle, in uv_process_tty_read_raw_req()
750 records_left--; in uv_process_tty_read_raw_req()
754 if (handle->tty.rd.last_input_record.EventType == WINDOW_BUFFER_SIZE_EVENT) { in uv_process_tty_read_raw_req()
759 if (handle->tty.rd.last_input_record.EventType != KEY_EVENT) { in uv_process_tty_read_raw_req()
760 continue; in uv_process_tty_read_raw_req()
768 continue; in uv_process_tty_read_raw_req()
796 continue; in uv_process_tty_read_raw_req()
807 /* UTF-16 high surrogate */ in uv_process_tty_read_raw_req()
808 handle->tty.rd.last_utf16_high_surrogate = KEV.uChar.UnicodeChar; in uv_process_tty_read_raw_req()
809 continue; in uv_process_tty_read_raw_req()
817 handle->tty.rd.last_key[0] = '\033'; in uv_process_tty_read_raw_req()
823 char_len = sizeof handle->tty.rd.last_key; in uv_process_tty_read_raw_req()
824 last_key_buf = &handle->tty.rd.last_key[prefix_len]; in uv_process_tty_read_raw_req()
825 if (handle->tty.rd.last_utf16_high_surrogate) { in uv_process_tty_read_raw_req()
826 /* UTF-16 surrogate pair */ in uv_process_tty_read_raw_req()
828 utf16_buffer[0] = handle->tty.rd.last_utf16_high_surrogate; in uv_process_tty_read_raw_req()
835 handle->tty.rd.last_utf16_high_surrogate = 0; in uv_process_tty_read_raw_req()
837 /* Single UTF-16 character */ in uv_process_tty_read_raw_req()
848 handle->flags &= ~UV_HANDLE_READING; in uv_process_tty_read_raw_req()
850 handle->read_cb((uv_stream_t*) handle, in uv_process_tty_read_raw_req()
856 handle->tty.rd.last_key_len = (unsigned char) (prefix_len + char_len); in uv_process_tty_read_raw_req()
857 handle->tty.rd.last_key_offset = 0; in uv_process_tty_read_raw_req()
858 continue; in uv_process_tty_read_raw_req()
874 continue; in uv_process_tty_read_raw_req()
879 handle->tty.rd.last_key[0] = '\033'; in uv_process_tty_read_raw_req()
886 assert(prefix_len + vt100_len < sizeof handle->tty.rd.last_key); in uv_process_tty_read_raw_req()
887 memcpy(&handle->tty.rd.last_key[prefix_len], vt100, vt100_len); in uv_process_tty_read_raw_req()
889 handle->tty.rd.last_key_len = (unsigned char) (prefix_len + vt100_len); in uv_process_tty_read_raw_req()
890 handle->tty.rd.last_key_offset = 0; in uv_process_tty_read_raw_req()
891 continue; in uv_process_tty_read_raw_req()
895 if (handle->tty.rd.last_key_offset < handle->tty.rd.last_key_len) { in uv_process_tty_read_raw_req()
899 handle->alloc_cb((uv_handle_t*) handle, 1024, &buf); in uv_process_tty_read_raw_req()
901 handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf); in uv_process_tty_read_raw_req()
907 buf.base[buf_used++] = handle->tty.rd.last_key[handle->tty.rd.last_key_offset++]; in uv_process_tty_read_raw_req()
911 handle->read_cb((uv_stream_t*) handle, buf_used, &buf); in uv_process_tty_read_raw_req()
916 continue; in uv_process_tty_read_raw_req()
920 if (--KEV.wRepeatCount > 0) { in uv_process_tty_read_raw_req()
921 handle->tty.rd.last_key_offset = 0; in uv_process_tty_read_raw_req()
922 continue; in uv_process_tty_read_raw_req()
925 handle->tty.rd.last_key_len = 0; in uv_process_tty_read_raw_req()
926 continue; in uv_process_tty_read_raw_req()
932 handle->read_cb((uv_stream_t*) handle, buf_used, &buf); in uv_process_tty_read_raw_req()
937 if ((handle->flags & UV_HANDLE_READING) && in uv_process_tty_read_raw_req()
938 !(handle->flags & UV_HANDLE_READ_PENDING)) { in uv_process_tty_read_raw_req()
953 assert(handle->type == UV_TTY); in uv_process_tty_read_line_req()
954 assert(handle->flags & UV_HANDLE_TTY_READABLE); in uv_process_tty_read_line_req()
956 buf = handle->tty.rd.read_line_buffer; in uv_process_tty_read_line_req()
958 handle->flags &= ~UV_HANDLE_READ_PENDING; in uv_process_tty_read_line_req()
959 handle->tty.rd.read_line_buffer = uv_null_buf_; in uv_process_tty_read_line_req()
963 if (handle->flags & UV_HANDLE_READING) { in uv_process_tty_read_line_req()
964 /* Real error */ in uv_process_tty_read_line_req()
965 handle->flags &= ~UV_HANDLE_READING; in uv_process_tty_read_line_req()
967 handle->read_cb((uv_stream_t*) handle, in uv_process_tty_read_line_req()
972 if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING) && in uv_process_tty_read_line_req()
973 req->u.io.overlapped.InternalHigh != 0) { in uv_process_tty_read_line_req()
974 /* Read successful. TODO: read unicode, convert to utf-8 */ in uv_process_tty_read_line_req()
975 DWORD bytes = req->u.io.overlapped.InternalHigh; in uv_process_tty_read_line_req()
976 handle->read_cb((uv_stream_t*) handle, bytes, &buf); in uv_process_tty_read_line_req()
978 handle->flags &= ~UV_HANDLE_CANCELLATION_PENDING; in uv_process_tty_read_line_req()
982 if ((handle->flags & UV_HANDLE_READING) && in uv_process_tty_read_line_req()
983 !(handle->flags & UV_HANDLE_READ_PENDING)) { in uv_process_tty_read_line_req()
993 assert(handle->type == UV_TTY); in uv__process_tty_read_req()
994 assert(handle->flags & UV_HANDLE_TTY_READABLE); in uv__process_tty_read_req()
997 * Otherwise it was a line-buffered read. FIXME: This is quite obscure. Use a in uv__process_tty_read_req()
999 if (handle->tty.rd.read_line_buffer.len == 0) { in uv__process_tty_read_req()
1009 uv_loop_t* loop = handle->loop; in uv__tty_read_start()
1011 if (!(handle->flags & UV_HANDLE_TTY_READABLE)) { in uv__tty_read_start()
1015 handle->flags |= UV_HANDLE_READING; in uv__tty_read_start()
1017 handle->read_cb = read_cb; in uv__tty_read_start()
1018 handle->alloc_cb = alloc_cb; in uv__tty_read_start()
1022 if (handle->flags & UV_HANDLE_READ_PENDING) { in uv__tty_read_start()
1026 /* Maybe the user stopped reading half-way while processing key events. in uv__tty_read_start()
1027 * Short-circuit if this could be the case. */ in uv__tty_read_start()
1028 if (handle->tty.rd.last_key_len > 0) { in uv__tty_read_start()
1029 SET_REQ_SUCCESS(&handle->read_req); in uv__tty_read_start()
1030 uv__insert_pending_req(handle->loop, (uv_req_t*) &handle->read_req); in uv__tty_read_start()
1032 handle->flags |= UV_HANDLE_READ_PENDING; in uv__tty_read_start()
1033 handle->reqs_pending++; in uv__tty_read_start()
1047 handle->flags &= ~UV_HANDLE_READING; in uv__tty_read_stop()
1048 DECREASE_ACTIVE_COUNT(handle->loop, handle); in uv__tty_read_stop()
1050 if (!(handle->flags & UV_HANDLE_READ_PENDING)) in uv__tty_read_stop()
1053 if (handle->flags & UV_HANDLE_TTY_RAW) { in uv__tty_read_stop()
1058 if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) { in uv__tty_read_stop()
1061 } else if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING)) { in uv__tty_read_stop()
1062 /* Cancel line-buffered read if not already pending */ in uv__tty_read_stop()
1067 handle->flags |= UV_HANDLE_CANCELLATION_PENDING; in uv__tty_read_stop()
1080 assert(!(handle->flags & UV_HANDLE_CANCELLATION_PENDING)); in uv__cancel_read_console()
1119 if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) in uv__cancel_read_console()
1130 uv_tty_virtual_width = info->dwSize.X; in uv__tty_update_virtual_window()
1131 uv_tty_virtual_height = info->srWindow.Bottom - info->srWindow.Top + 1; in uv__tty_update_virtual_window()
1134 if (uv_tty_virtual_offset == -1) { in uv__tty_update_virtual_window()
1135 uv_tty_virtual_offset = info->dwCursorPosition.Y; in uv__tty_update_virtual_window()
1136 } else if (uv_tty_virtual_offset < info->dwCursorPosition.Y - in uv__tty_update_virtual_window()
1140 uv_tty_virtual_offset = info->dwCursorPosition.Y - in uv__tty_update_virtual_window()
1143 if (uv_tty_virtual_offset + uv_tty_virtual_height > info->dwSize.Y) { in uv__tty_update_virtual_window()
1144 uv_tty_virtual_offset = info->dwSize.Y - uv_tty_virtual_height; in uv__tty_update_virtual_window()
1161 y = info->dwCursorPosition.Y + y; in uv__tty_make_real_coord()
1169 y = uv_tty_virtual_offset + uv_tty_virtual_height - 1; in uv__tty_make_real_coord()
1174 x = info->dwCursorPosition.X + x; in uv__tty_make_real_coord()
1180 x = uv_tty_virtual_width - 1; in uv__tty_make_real_coord()
1190 DWORD* error) { in uv__tty_emit_text() argument
1193 if (*error != ERROR_SUCCESS) { in uv__tty_emit_text()
1194 return -1; in uv__tty_emit_text()
1197 if (!WriteConsoleW(handle->handle, in uv__tty_emit_text()
1202 *error = GetLastError(); in uv__tty_emit_text()
1203 return -1; in uv__tty_emit_text()
1211 int y, unsigned char y_relative, DWORD* error) { in uv__tty_move_caret() argument
1215 if (*error != ERROR_SUCCESS) { in uv__tty_move_caret()
1216 return -1; in uv__tty_move_caret()
1220 if (!GetConsoleScreenBufferInfo(handle->handle, &info)) { in uv__tty_move_caret()
1221 *error = GetLastError(); in uv__tty_move_caret()
1226 if (!SetConsoleCursorPosition(handle->handle, pos)) { in uv__tty_move_caret()
1228 /* The console may be resized - retry */ in uv__tty_move_caret()
1231 *error = GetLastError(); in uv__tty_move_caret()
1232 return -1; in uv__tty_move_caret()
1240 static int uv__tty_reset(uv_tty_t* handle, DWORD* error) { in uv__tty_reset() argument
1246 if (*error != ERROR_SUCCESS) { in uv__tty_reset()
1247 return -1; in uv__tty_reset()
1251 if (!SetConsoleTextAttribute(handle->handle, char_attrs)) { in uv__tty_reset()
1252 *error = GetLastError(); in uv__tty_reset()
1253 return -1; in uv__tty_reset()
1257 if (!SetConsoleCursorPosition(handle->handle, origin)) { in uv__tty_reset()
1258 *error = GetLastError(); in uv__tty_reset()
1259 return -1; in uv__tty_reset()
1264 if (!GetConsoleScreenBufferInfo(handle->handle, &screen_buffer_info)) { in uv__tty_reset()
1265 *error = GetLastError(); in uv__tty_reset()
1266 return -1; in uv__tty_reset()
1271 if (!(FillConsoleOutputCharacterW(handle->handle, in uv__tty_reset()
1276 FillConsoleOutputAttribute(handle->handle, in uv__tty_reset()
1282 /* The console may be resized - retry */ in uv__tty_reset()
1285 *error = GetLastError(); in uv__tty_reset()
1286 return -1; in uv__tty_reset()
1295 if (!SetConsoleCursorInfo(handle->handle, &uv_tty_default_cursor_info)) { in uv__tty_reset()
1296 *error = GetLastError(); in uv__tty_reset()
1297 return -1; in uv__tty_reset()
1305 DWORD* error) { in uv__tty_clear() argument
1313 if (*error != ERROR_SUCCESS) { in uv__tty_clear()
1314 return -1; in uv__tty_clear()
1339 /* Stay on our own row */ in uv__tty_clear()
1351 if (!GetConsoleScreenBufferInfo(handle->handle, &info)) { in uv__tty_clear()
1352 *error = GetLastError(); in uv__tty_clear()
1353 return -1; in uv__tty_clear()
1358 count = (end.Y * info.dwSize.X + end.X) - in uv__tty_clear()
1361 if (!(FillConsoleOutputCharacterW(handle->handle, in uv__tty_clear()
1366 FillConsoleOutputAttribute(handle->handle, in uv__tty_clear()
1372 /* The console may be resized - retry */ in uv__tty_clear()
1375 *error = GetLastError(); in uv__tty_clear()
1376 return -1; in uv__tty_clear()
1392 static int uv__tty_set_style(uv_tty_t* handle, DWORD* error) { in uv__tty_set_style() argument
1393 unsigned short argc = handle->tty.wr.ansi_csi_argc; in uv__tty_set_style()
1394 unsigned short* argv = handle->tty.wr.ansi_csi_argv; in uv__tty_set_style()
1398 char fg_color = -1, bg_color = -1; in uv__tty_set_style()
1399 char fg_bright = -1, bg_bright = -1; in uv__tty_set_style()
1400 char inverse = -1; in uv__tty_set_style()
1423 /* Foreground bright on */ in uv__tty_set_style()
1432 /* Background bright on */ in uv__tty_set_style()
1436 /* Inverse: on */ in uv__tty_set_style()
1453 fg_color = arg - 30; in uv__tty_set_style()
1462 bg_color = arg - 40; in uv__tty_set_style()
1472 fg_color = arg - 90; in uv__tty_set_style()
1477 bg_color = arg - 100; in uv__tty_set_style()
1482 if (fg_color == -1 && bg_color == -1 && fg_bright == -1 && in uv__tty_set_style()
1483 bg_bright == -1 && inverse == -1) { in uv__tty_set_style()
1488 if (!GetConsoleScreenBufferInfo(handle->handle, &info)) { in uv__tty_set_style()
1489 *error = GetLastError(); in uv__tty_set_style()
1490 return -1; in uv__tty_set_style()
1497 if (fg_color != -1) { in uv__tty_set_style()
1504 if (fg_bright != -1) { in uv__tty_set_style()
1512 if (bg_color != -1) { in uv__tty_set_style()
1519 if (bg_bright != -1) { in uv__tty_set_style()
1527 if (inverse != -1) { in uv__tty_set_style()
1539 if (!SetConsoleTextAttribute(handle->handle, info.wAttributes)) { in uv__tty_set_style()
1540 *error = GetLastError(); in uv__tty_set_style()
1541 return -1; in uv__tty_set_style()
1549 DWORD* error) { in uv__tty_save_state() argument
1552 if (*error != ERROR_SUCCESS) { in uv__tty_save_state()
1553 return -1; in uv__tty_save_state()
1556 if (!GetConsoleScreenBufferInfo(handle->handle, &info)) { in uv__tty_save_state()
1557 *error = GetLastError(); in uv__tty_save_state()
1558 return -1; in uv__tty_save_state()
1563 handle->tty.wr.saved_position.X = info.dwCursorPosition.X; in uv__tty_save_state()
1564 handle->tty.wr.saved_position.Y = info.dwCursorPosition.Y - in uv__tty_save_state()
1566 handle->flags |= UV_HANDLE_TTY_SAVED_POSITION; in uv__tty_save_state()
1569 handle->tty.wr.saved_attributes = info.wAttributes & in uv__tty_save_state()
1571 handle->flags |= UV_HANDLE_TTY_SAVED_ATTRIBUTES; in uv__tty_save_state()
1579 unsigned char restore_attributes, DWORD* error) { in uv__tty_restore_state() argument
1583 if (*error != ERROR_SUCCESS) { in uv__tty_restore_state()
1584 return -1; in uv__tty_restore_state()
1587 if (handle->flags & UV_HANDLE_TTY_SAVED_POSITION) { in uv__tty_restore_state()
1589 handle->tty.wr.saved_position.X, in uv__tty_restore_state()
1591 handle->tty.wr.saved_position.Y, in uv__tty_restore_state()
1593 error) != 0) { in uv__tty_restore_state()
1594 return -1; in uv__tty_restore_state()
1599 (handle->flags & UV_HANDLE_TTY_SAVED_ATTRIBUTES)) { in uv__tty_restore_state()
1600 if (!GetConsoleScreenBufferInfo(handle->handle, &info)) { in uv__tty_restore_state()
1601 *error = GetLastError(); in uv__tty_restore_state()
1602 return -1; in uv__tty_restore_state()
1607 new_attributes |= handle->tty.wr.saved_attributes; in uv__tty_restore_state()
1609 if (!SetConsoleTextAttribute(handle->handle, new_attributes)) { in uv__tty_restore_state()
1610 *error = GetLastError(); in uv__tty_restore_state()
1611 return -1; in uv__tty_restore_state()
1620 DWORD* error) { in uv__tty_set_cursor_visibility() argument
1623 if (!GetConsoleCursorInfo(handle->handle, &cursor_info)) { in uv__tty_set_cursor_visibility()
1624 *error = GetLastError(); in uv__tty_set_cursor_visibility()
1625 return -1; in uv__tty_set_cursor_visibility()
1630 if (!SetConsoleCursorInfo(handle->handle, &cursor_info)) { in uv__tty_set_cursor_visibility()
1631 *error = GetLastError(); in uv__tty_set_cursor_visibility()
1632 return -1; in uv__tty_set_cursor_visibility()
1638 static int uv__tty_set_cursor_shape(uv_tty_t* handle, int style, DWORD* error) { in uv__tty_set_cursor_shape() argument
1641 if (!GetConsoleCursorInfo(handle->handle, &cursor_info)) { in uv__tty_set_cursor_shape()
1642 *error = GetLastError(); in uv__tty_set_cursor_shape()
1643 return -1; in uv__tty_set_cursor_shape()
1654 if (!SetConsoleCursorInfo(handle->handle, &cursor_info)) { in uv__tty_set_cursor_shape()
1655 *error = GetLastError(); in uv__tty_set_cursor_shape()
1656 return -1; in uv__tty_set_cursor_shape()
1666 DWORD* error) { argument
1676 uv__tty_emit_text(handle, utf16_buf, utf16_buf_used, error); \
1682 if (wchars_needed > ARRAY_SIZE(utf16_buf) - utf16_buf_used) { \
1687 unsigned char utf8_bytes_left = handle->tty.wr.utf8_bytes_left;
1688 unsigned int utf8_codepoint = handle->tty.wr.utf8_codepoint;
1689 unsigned char previous_eol = handle->tty.wr.previous_eol;
1690 unsigned short ansi_parser_state = handle->tty.wr.ansi_parser_state;
1692 /* Store the error here. If we encounter an error, stop trying to do i/o but
1694 *error = ERROR_SUCCESS;
1706 * shortest form encodings and invalid code points - there's no real harm
1709 /* Read utf-8 start byte */
1716 first_zero_bit = (sizeof(int) * 8) - 1 - __builtin_clz(not_c);
1719 /* Ascii - pass right through */
1724 utf8_codepoint = (0xff >> (8 - first_zero_bit)) & c;
1725 utf8_bytes_left = (char) (6 - first_zero_bit);
1733 /* 0xff -- invalid */
1738 /* Valid continuation of utf-8 multibyte sequence */
1739 utf8_bytes_left--;
1749 j--;
1754 continue;
1764 continue;
1768 handle->tty.wr.ansi_csi_argc = 0;
1769 continue;
1776 handle->tty.wr.ansi_csi_argc = 0;
1777 continue;
1786 continue;
1790 continue;
1795 uv__tty_reset(handle, error);
1797 continue;
1802 uv__tty_save_state(handle, 1, error);
1804 continue;
1809 uv__tty_restore_state(handle, 1, error);
1811 continue;
1815 /* Single-char control. */
1817 continue;
1819 /* Invalid - proceed as normal, */
1825 /* We're ignoring this command. Stop only on command character. */
1829 continue;
1838 int style = handle->tty.wr.ansi_csi_argc
1839 ? handle->tty.wr.ansi_csi_argv[0] : 1;
1842 uv__tty_set_cursor_shape(handle, style, error);
1846 /* Sequence ended - go back to normal state. */
1848 continue;
1863 if (handle->tty.wr.ansi_csi_argc >=
1864 ARRAY_SIZE(handle->tty.wr.ansi_csi_argv)) {
1866 continue;
1869 handle->tty.wr.ansi_csi_argc++;
1870 handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1] =
1871 (unsigned short) utf8_codepoint - '0';
1872 continue;
1877 handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1];
1882 continue;
1885 handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1] =
1886 (unsigned short) value + (utf8_codepoint - '0');
1887 continue;
1894 continue;
1901 if (handle->tty.wr.ansi_csi_argc >=
1903 ARRAY_SIZE(handle->tty.wr.ansi_csi_argv)) {
1905 continue;
1908 handle->tty.wr.ansi_csi_argc++;
1909 handle->tty.wr.ansi_csi_argv[handle->tty.wr.ansi_csi_argc - 1] = 0;
1910 continue;
1916 handle->tty.wr.ansi_csi_argc == 0) {
1921 continue;
1928 continue;
1937 if (handle->tty.wr.ansi_csi_argc == 1 &&
1938 handle->tty.wr.ansi_csi_argv[0] == 25) {
1940 uv__tty_set_cursor_visibility(handle, 0, error);
1946 if (handle->tty.wr.ansi_csi_argc == 1 &&
1947 handle->tty.wr.ansi_csi_argv[0] == 25) {
1949 uv__tty_set_cursor_visibility(handle, 1, error);
1961 y = -(handle->tty.wr.ansi_csi_argc
1962 ? handle->tty.wr.ansi_csi_argv[0] : 1);
1963 uv__tty_move_caret(handle, 0, 1, y, 1, error);
1969 y = handle->tty.wr.ansi_csi_argc
1970 ? handle->tty.wr.ansi_csi_argv[0] : 1;
1971 uv__tty_move_caret(handle, 0, 1, y, 1, error);
1977 x = handle->tty.wr.ansi_csi_argc
1978 ? handle->tty.wr.ansi_csi_argv[0] : 1;
1979 uv__tty_move_caret(handle, x, 1, 0, 1, error);
1985 x = -(handle->tty.wr.ansi_csi_argc
1986 ? handle->tty.wr.ansi_csi_argv[0] : 1);
1987 uv__tty_move_caret(handle, x, 1, 0, 1, error);
1993 y = handle->tty.wr.ansi_csi_argc
1994 ? handle->tty.wr.ansi_csi_argv[0] : 1;
1995 uv__tty_move_caret(handle, 0, 0, y, 1, error);
2001 y = -(handle->tty.wr.ansi_csi_argc
2002 ? handle->tty.wr.ansi_csi_argv[0] : 1);
2003 uv__tty_move_caret(handle, 0, 0, y, 1, error);
2009 x = (handle->tty.wr.ansi_csi_argc >= 1 &&
2010 handle->tty.wr.ansi_csi_argv[0])
2011 ? handle->tty.wr.ansi_csi_argv[0] - 1 : 0;
2012 uv__tty_move_caret(handle, x, 0, 0, 1, error);
2019 y = (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;
2022 x = (handle->tty.wr.ansi_csi_argc >= 2 &&
2023 handle->tty.wr.ansi_csi_argv[1])
2024 ? handle->tty.wr.ansi_csi_argv[1] - 1 : 0;
2025 uv__tty_move_caret(handle, x, 0, y, 0, error);
2031 d = handle->tty.wr.ansi_csi_argc
2032 ? handle->tty.wr.ansi_csi_argv[0] : 0;
2034 uv__tty_clear(handle, d, 1, error);
2041 d = handle->tty.wr.ansi_csi_argc
2042 ? handle->tty.wr.ansi_csi_argv[0] : 0;
2044 uv__tty_clear(handle, d, 0, error);
2051 uv__tty_set_style(handle, error);
2057 uv__tty_save_state(handle, 0, error);
2063 uv__tty_restore_state(handle, 0, error);
2068 /* Sequence ended - go back to normal state. */
2070 continue;
2076 continue;
2109 continue;
2116 /* EOL conversion - emit \r\n when we see \n. */
2129 /* \r without \n; print \r as-is. */
2137 /* Encode character into utf-16 buffer. */
2143 utf8_codepoint -= 0x10000;
2155 handle->tty.wr.utf8_bytes_left = utf8_bytes_left;
2156 handle->tty.wr.utf8_codepoint = utf8_codepoint;
2157 handle->tty.wr.previous_eol = previous_eol;
2158 handle->tty.wr.ansi_parser_state = ansi_parser_state;
2162 if (*error == STATUS_SUCCESS) {
2165 return -1;
2178 DWORD error; local
2181 req->handle = (uv_stream_t*) handle;
2182 req->cb = cb;
2184 handle->reqs_pending++;
2185 handle->stream.conn.write_reqs_pending++;
2188 req->u.io.queued_bytes = 0;
2190 if (!uv__tty_write_bufs(handle, bufs, nbufs, &error)) {
2193 SET_REQ_ERROR(req, error);
2205 DWORD error; local
2207 if (handle->stream.conn.write_reqs_pending > 0)
2210 if (uv__tty_write_bufs(handle, bufs, nbufs, &error))
2211 return uv_translate_sys_error(error);
2221 handle->write_queue_size -= req->u.io.queued_bytes;
2224 if (req->cb) {
2226 req->cb(req, uv_translate_sys_error(err));
2230 handle->stream.conn.write_reqs_pending--;
2231 if (handle->stream.conn.write_reqs_pending == 0 &&
2235 handle->stream.conn.shutdown_req);
2242 assert(handle->u.fd == -1 || handle->u.fd > 2);
2243 if (handle->flags & UV_HANDLE_READING)
2246 if (handle->u.fd == -1)
2247 CloseHandle(handle->handle);
2249 _close(handle->u.fd);
2251 handle->u.fd = -1;
2252 handle->handle = INVALID_HANDLE_VALUE;
2253 handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
2256 if (handle->reqs_pending == 0)
2257 uv__want_endgame(handle->loop, (uv_handle_t*) handle);
2262 assert(stream->stream.conn.write_reqs_pending == 0);
2265 stream->stream.conn.shutdown_req = NULL;
2268 /* TTY shutdown is really just a no-op */
2269 if (req->cb) {
2270 if (stream->flags & UV_HANDLE_CLOSING) {
2271 req->cb(req, UV_ECANCELED);
2273 req->cb(req, 0);
2282 assert(handle->flags & UV_HANDLE_CLOSING);
2283 assert(handle->reqs_pending == 0);
2287 assert(!(handle->flags & UV_HANDLE_TTY_READABLE) ||
2288 handle->tty.rd.read_raw_wait == NULL);
2290 assert(!(handle->flags & UV_HANDLE_CLOSED));
2336 * is a 32-bit process running on 64-bit Windows. Fall back to receiving
2397 height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1;