📄 fhandler_console.cc
字号:
switch (dev_state->args_[0]) { case 6: /* u7 - Cursor position request */ cursor_get (&x, &y); y -= dev_state->info.winTop; /* x -= dev_state->info.winLeft; // not available yet */ __small_sprintf (buf, "\033[%d;%dR", y + 1, x + 1); puts_readahead (buf); break; default: goto bad_escape; } break; case 'r': /* Set Scroll region */ dev_state->scroll_region.Top = dev_state->args_[0] ? dev_state->args_[0] - 1 : 0; dev_state->scroll_region.Bottom = dev_state->args_[1] ? dev_state->args_[1] - 1 : -1; cursor_set (TRUE, 0, 0); break; case 'g': /* TAB set/clear */ break; default:bad_escape: break; }}const unsigned char *fhandler_console::write_normal (const unsigned char *src, const unsigned char *end){ /* Scan forward to see what a char which needs special treatment */ DWORD done; const unsigned char *found = src; while (found < end) { if (base_chars[*found] != NOR) break; found++; } /* Print all the base ones out */ if (found != src) { DWORD len = found - src; do { DWORD buf_len; char buf[CONVERT_LIMIT]; done = buf_len = min (sizeof (buf), len); if (!str_to_con (buf, (const char *) src, buf_len)) { debug_printf ("conversion error, handle %p", get_output_handle ()); __seterrno (); return 0; } if (dev_state->insert_mode) { int x, y; cursor_get (&x, &y); scroll_screen (x, y, -1, y, x + buf_len, y); } if (!WriteFile (get_output_handle (), buf, buf_len, &done, 0)) { debug_printf ("write failed, handle %p", get_output_handle ()); __seterrno (); return 0; } len -= done; src += done; } while (len > 0); } if (src < end) { int x, y; switch (base_chars[*src]) { case BEL: Beep (412, 100); break; case ESC: dev_state->state_ = gotesc; break; case DWN: cursor_get (&x, &y); if (y >= srBottom) { if (y >= dev_state->info.winBottom && !dev_state->scroll_region.Top) WriteFile (get_output_handle (), "\n", 1, &done, 0); else { scroll_screen (0, srTop + 1, -1, srBottom, 0, srTop); y--; } } cursor_set (FALSE, ((tc->ti.c_oflag & ONLCR) ? 0 : x), y + 1); break; case BAK: cursor_rel (-1, 0); break; case IGN: cursor_rel (1, 0); break; case CR: cursor_get (&x, &y); cursor_set (FALSE, 0, y); break; case ERR: WriteFile (get_output_handle (), src, 1, &done, 0); break; case TAB: cursor_get (&x, &y); cursor_set (FALSE, 8 * (x / 8 + 1), y); break; } src ++; } return src;}intfhandler_console::write (const void *vsrc, size_t len){ /* Run and check for ansi sequences */ unsigned const char *src = (unsigned char *) vsrc; unsigned const char *end = src + len; debug_printf ("%x, %d", vsrc, len); while (src < end) { debug_printf ("at %d(%c) state is %d", *src, isprint (*src) ? *src : ' ', dev_state->state_); switch (dev_state->state_) { case normal: src = write_normal (src, end); if (!src) /* write_normal failed */ return -1; break; case gotesc: if (*src == '[') { dev_state->state_ = gotsquare; dev_state->saw_question_mark = FALSE; for (dev_state->nargs_ = 0; dev_state->nargs_ < MAXARGS; dev_state->nargs_++) dev_state->args_[dev_state->nargs_] = 0; dev_state->nargs_ = 0; } else if (*src == ']') { dev_state->rarg = 0; dev_state->my_title_buf[0] = '\0'; dev_state->state_ = gotrsquare; } else if (*src == 'M') /* Reverse Index */ { fillin_info (); scroll_screen (0, 0, -1, -1, 0, dev_state->info.winTop + 1); dev_state->state_ = normal; } else if (*src == 'c') /* Reset Linux terminal */ { set_default_attr (); clear_screen (0, 0, -1, -1); cursor_set (TRUE, 0, 0); dev_state->state_ = normal; } else if (*src == '8') /* Restore cursor position */ { cursor_set (TRUE, dev_state->savex, dev_state->savey); dev_state->state_ = normal; } else if (*src == '7') /* Save cursor position */ { cursor_get (&dev_state->savex, &dev_state->savey); dev_state->savey -= dev_state->info.winTop; dev_state->state_ = normal; } else if (*src == 'R') dev_state->state_ = normal; else { dev_state->state_ = normal; } src++; break; case gotarg1: if (isdigit (*src)) { dev_state->args_[dev_state->nargs_] = dev_state->args_[dev_state->nargs_] * 10 + *src - '0'; src++; } else if (*src == ';') { src++; dev_state->nargs_++; if (dev_state->nargs_ >= MAXARGS) dev_state->nargs_--; } else { dev_state->state_ = gotcommand; } break; case gotcommand: char_command (*src++); dev_state->state_ = normal; break; case gotrsquare: if (isdigit (*src)) dev_state->rarg = dev_state->rarg * 10 + (*src - '0'); else if (*src == ';' && (dev_state->rarg == 2 || dev_state->rarg == 0)) dev_state->state_ = gettitle; else dev_state->state_ = eattitle; src++; break; case eattitle: case gettitle: { int n = strlen (dev_state->my_title_buf); if (*src < ' ') { if (*src == '\007' && dev_state->state_ == gettitle) { if (old_title) strcpy (old_title, dev_state->my_title_buf); set_console_title (dev_state->my_title_buf); } dev_state->state_ = normal; } else if (n < TITLESIZE) { dev_state->my_title_buf[n++] = *src; dev_state->my_title_buf[n] = '\0'; } src++; break; } case gotsquare: if (*src == ';') { dev_state->state_ = gotarg1; dev_state->nargs_++; src++; } else if (isalpha (*src)) dev_state->state_ = gotcommand; else if (*src != '@' && !isalpha (*src) && !isdigit (*src)) { if (*src == '?') dev_state->saw_question_mark = TRUE; /* ignore any extra chars between [ and first arg or command */ src++; } else dev_state->state_ = gotarg1; break; } } syscall_printf ("%d = write_console (,..%d)", len, len); return len;}static struct { int vk; const char *val[4];} keytable[] NO_COPY = { /* NORMAL */ /* SHIFT */ /* CTRL */ /* ALT */ {VK_LEFT, {"\033[D", "\033[D", "\033[D", "\033\033[D"}}, {VK_RIGHT, {"\033[C", "\033[C", "\033[C", "\033\033[C"}}, {VK_UP, {"\033[A", "\033[A", "\033[A", "\033\033[A"}}, {VK_DOWN, {"\033[B", "\033[B", "\033[B", "\033\033[B"}}, {VK_PRIOR, {"\033[5~", "\033[5~", "\033[5~", "\033\033[5~"}}, {VK_NEXT, {"\033[6~", "\033[6~", "\033[6~", "\033\033[6~"}}, {VK_HOME, {"\033[1~", "\033[1~", "\033[1~", "\033\033[1~"}}, {VK_END, {"\033[4~", "\033[4~", "\033[4~", "\033\033[4~"}}, {VK_INSERT, {"\033[2~", "\033[2~", "\033[2~", "\033\033[2~"}}, {VK_DELETE, {"\033[3~", "\033[3~", "\033[3~", "\033\033[3~"}}, {VK_F1, {"\033[[A", "\033[23~", NULL, NULL}}, {VK_F2, {"\033[[B", "\033[24~", NULL, NULL}}, {VK_F3, {"\033[[C", "\033[25~", NULL, NULL}}, {VK_F4, {"\033[[D", "\033[26~", NULL, NULL}}, {VK_F5, {"\033[[E", "\033[28~", NULL, NULL}}, {VK_F6, {"\033[17~", "\033[29~", "\036", NULL}}, {VK_F7, {"\033[18~", "\033[31~", NULL, NULL}}, {VK_F8, {"\033[19~", "\033[32~", NULL, NULL}}, {VK_F9, {"\033[20~", "\033[33~", NULL, NULL}}, {VK_F10, {"\033[21~", "\033[34~", NULL, NULL}}, {VK_F11, {"\033[23~", NULL, NULL, NULL}}, {VK_F12, {"\033[24~", NULL, NULL, NULL}}, {VK_NUMPAD5, {"\033[G", NULL, NULL, NULL}}, {VK_CLEAR, {"\033[G", NULL, NULL, NULL}}, {'6', {NULL, NULL, "\036", NULL}}, {0, {"", NULL, NULL, NULL}}};const char *get_nonascii_key (INPUT_RECORD& input_rec, char *tmp){#define NORMAL 0#define SHIFT 1#define CONTROL 2#define ALT 3 int modifier_index = NORMAL; if (input_rec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) modifier_index = SHIFT; else if (input_rec.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) modifier_index = CONTROL; else if (input_rec.Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) modifier_index = ALT; for (int i = 0; keytable[i].vk; i++) if (input_rec.Event.KeyEvent.wVirtualKeyCode == keytable[i].vk) return keytable[i].val[modifier_index]; if (input_rec.Event.KeyEvent.uChar.AsciiChar) { tmp[0] = input_rec.Event.KeyEvent.uChar.AsciiChar; tmp[1] = '\0'; return tmp; } return NULL;}voidfhandler_console::init (HANDLE f, DWORD a, mode_t bin){ // this->fhandler_termios::init (f, mode, bin); /* Ensure both input and output console handles are open */ int flags = 0; a &= GENERIC_READ | GENERIC_WRITE; if (a == GENERIC_READ) flags = O_RDONLY; if (a == GENERIC_WRITE) flags = O_WRONLY; if (a == (GENERIC_READ | GENERIC_WRITE)) flags = O_RDWR; open ((path_conv *) NULL, flags | O_BINARY); if (f != INVALID_HANDLE_VALUE) CloseHandle (f); /* Reopened by open */ this->tcsetattr (0, &tc->ti);}intfhandler_console::igncr_enabled (void){ return tc->ti.c_iflag & IGNCR;}voidfhandler_console::set_close_on_exec (int val){ this->fhandler_base::set_close_on_exec (val); set_inheritance (output_handle, val);}voidfhandler_console::fixup_after_fork (HANDLE){ HANDLE h = get_handle (); HANDLE oh = get_output_handle (); /* Windows does not allow duplication of console handles between processes so open the console explicitly. */ if (!open (NULL, O_NOCTTY | get_flags (), 0)) system_printf ("error opening console after fork, %E"); if (!get_close_on_exec ()) { CloseHandle (h); CloseHandle (oh); }}void __stdcallset_console_title (char *title){ int rc; char buf[257]; strncpy (buf, title, sizeof (buf) - 1); buf[sizeof (buf) - 1] = '\0'; if ((rc = WaitForSingleObject (title_mutex, 15000)) != WAIT_OBJECT_0) sigproc_printf ("wait for title mutex failed rc %d, %E", rc); SetConsoleTitle (buf); ReleaseMutex (title_mutex); debug_printf ("title '%s'", buf);}voidfhandler_console::fixup_after_exec (HANDLE){ HANDLE h = get_handle (); HANDLE oh = get_output_handle (); if (!open (NULL, O_NOCTTY | get_flags (), 0)) { int sawerr = 0; if (!get_io_handle ()) { system_printf ("error opening input console handle after exec, errno %d, %E", get_errno ()); sawerr = 1; } if (!get_output_handle ()) { system_printf ("error opening input console handle after exec, errno %d, %E", get_errno ()); sawerr = 1; } if (!sawerr) system_printf ("error opening console after exec, errno %d, %E", get_errno ()); } CloseHandle (h); CloseHandle (oh); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -