📄 rltty.c
字号:
while (1) { ioctl_ret = GETATTR (tty, tiop); if (ioctl_ret < 0) { if (errno != EINTR) return -1; else continue; } if (OUTPUT_BEING_FLUSHED (tiop)) {#if defined (FLUSHO) && defined (_AIX41) rltty_warning ("turning off output flushing"); tiop->c_lflag &= ~FLUSHO; break;#else continue;#endif } break; } return 0;}static intget_tty_settings (tty, tiop) int tty; TIOTYPE *tiop;{ set_winsize (tty); if (_get_tty_settings (tty, tiop) < 0) return -1;#if defined (_AIX) setopost(tiop);#endif return 0;}static int_set_tty_settings (tty, tiop) int tty; TIOTYPE *tiop;{ while (SETATTR (tty, tiop) < 0) { if (errno != EINTR) return -1; errno = 0; } return 0;}static intset_tty_settings (tty, tiop) int tty; TIOTYPE *tiop;{ if (_set_tty_settings (tty, tiop) < 0) return -1; #if 0#if defined (TERMIOS_TTY_DRIVER)# if defined (__ksr1__) if (ksrflow) { ksrflow = 0; tcflow (tty, TCOON); }# else /* !ksr1 */ tcflow (tty, TCOON); /* Simulate a ^Q. */# endif /* !ksr1 */#else ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */#endif /* !TERMIOS_TTY_DRIVER */#endif /* 0 */ return 0;}static voidprepare_terminal_settings (meta_flag, oldtio, tiop) int meta_flag; TIOTYPE oldtio, *tiop;{ readline_echoing_p = (oldtio.c_lflag & ECHO); tiop->c_lflag &= ~(ICANON | ECHO); if ((unsigned char) oldtio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE) _rl_eof_char = oldtio.c_cc[VEOF];#if defined (USE_XON_XOFF)#if defined (IXANY) tiop->c_iflag &= ~(IXON | IXOFF | IXANY);#else /* `strict' Posix systems do not define IXANY. */ tiop->c_iflag &= ~(IXON | IXOFF);#endif /* IXANY */#endif /* USE_XON_XOFF */ /* Only turn this off if we are using all 8 bits. */ if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag) tiop->c_iflag &= ~(ISTRIP | INPCK); /* Make sure we differentiate between CR and NL on input. */ tiop->c_iflag &= ~(ICRNL | INLCR);#if !defined (HANDLE_SIGNALS) tiop->c_lflag &= ~ISIG;#else tiop->c_lflag |= ISIG;#endif tiop->c_cc[VMIN] = 1; tiop->c_cc[VTIME] = 0;#if defined (FLUSHO) if (OUTPUT_BEING_FLUSHED (tiop)) { tiop->c_lflag &= ~FLUSHO; oldtio.c_lflag &= ~FLUSHO; }#endif /* Turn off characters that we need on Posix systems with job control, just to be sure. This includes ^Y and ^V. This should not really be necessary. */#if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)#if defined (VLNEXT) tiop->c_cc[VLNEXT] = _POSIX_VDISABLE;#endif#if defined (VDSUSP) tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;#endif#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */}#endif /* NEW_TTY_DRIVER *//* Put the terminal in CBREAK mode so that we can detect key presses. */voidrl_prep_terminal (meta_flag) int meta_flag;{ int tty; TIOTYPE tio; if (terminal_prepped) return; /* Try to keep this function from being INTerrupted. */ block_sigint (); tty = fileno (rl_instream); if (get_tty_settings (tty, &tio) < 0) { release_sigint (); return; } otio = tio; rl_tty_unset_default_bindings (_rl_keymap); save_tty_chars (&otio); RL_SETSTATE(RL_STATE_TTYCSAVED); _rl_bind_tty_special_chars (_rl_keymap, tio); prepare_terminal_settings (meta_flag, otio, &tio); if (set_tty_settings (tty, &tio) < 0) { release_sigint (); return; } if (_rl_enable_keypad) _rl_control_keypad (1); fflush (rl_outstream); terminal_prepped = 1; RL_SETSTATE(RL_STATE_TERMPREPPED); release_sigint ();}/* Restore the terminal's normal settings and modes. */voidrl_deprep_terminal (){ int tty; if (!terminal_prepped) return; /* Try to keep this function from being interrupted. */ block_sigint (); tty = fileno (rl_instream); if (_rl_enable_keypad) _rl_control_keypad (0); fflush (rl_outstream); if (set_tty_settings (tty, &otio) < 0) { release_sigint (); return; } terminal_prepped = 0; RL_UNSETSTATE(RL_STATE_TERMPREPPED); release_sigint ();}/* **************************************************************** *//* *//* Bogus Flow Control *//* *//* **************************************************************** */intrl_restart_output (count, key) int count, key;{ int fildes = fileno (rl_outstream);#if defined (TIOCSTART)#if defined (apollo) ioctl (&fildes, TIOCSTART, 0);#else ioctl (fildes, TIOCSTART, 0);#endif /* apollo */#else /* !TIOCSTART */# if defined (TERMIOS_TTY_DRIVER)# if defined (__ksr1__) if (ksrflow) { ksrflow = 0; tcflow (fildes, TCOON); }# else /* !ksr1 */ tcflow (fildes, TCOON); /* Simulate a ^Q. */# endif /* !ksr1 */# else /* !TERMIOS_TTY_DRIVER */# if defined (TCXONC) ioctl (fildes, TCXONC, TCOON);# endif /* TCXONC */# endif /* !TERMIOS_TTY_DRIVER */#endif /* !TIOCSTART */ return 0;}intrl_stop_output (count, key) int count, key;{ int fildes = fileno (rl_instream);#if defined (TIOCSTOP)# if defined (apollo) ioctl (&fildes, TIOCSTOP, 0);# else ioctl (fildes, TIOCSTOP, 0);# endif /* apollo */#else /* !TIOCSTOP */# if defined (TERMIOS_TTY_DRIVER)# if defined (__ksr1__) ksrflow = 1;# endif /* ksr1 */ tcflow (fildes, TCOOFF);# else# if defined (TCXONC) ioctl (fildes, TCXONC, TCOON);# endif /* TCXONC */# endif /* !TERMIOS_TTY_DRIVER */#endif /* !TIOCSTOP */ return 0;}/* **************************************************************** *//* *//* Default Key Bindings *//* *//* **************************************************************** */#define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func)#if defined (NEW_TTY_DRIVER)static voidset_special_char (kmap, tiop, sc, func) Keymap kmap; TIOTYPE *tiop; int sc; rl_command_func_t *func;{ if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) kmap[(unsigned char)sc].function = func;}#define RESET_SPECIAL(c) \ if (c != -1 && kmap[(unsigned char)c].type == ISFUNC) kmap[(unsigned char)c].function = rl_insert;static void_rl_bind_tty_special_chars (kmap, ttybuff) Keymap kmap; TIOTYPE ttybuff;{ if (ttybuff.flags & SGTTY_SET) { SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); }# if defined (TIOCGLTC) if (ttybuff.flags & LTCHARS_SET) { SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); }# endif /* TIOCGLTC */}#else /* !NEW_TTY_DRIVER */static voidset_special_char (kmap, tiop, sc, func) Keymap kmap; TIOTYPE *tiop; int sc; rl_command_func_t *func;{ unsigned char uc; uc = tiop->c_cc[sc]; if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) kmap[uc].function = func;}/* used later */#define RESET_SPECIAL(uc) \ if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \ kmap[uc].function = rl_insert;static void_rl_bind_tty_special_chars (kmap, ttybuff) Keymap kmap; TIOTYPE ttybuff;{ SET_SPECIAL (VERASE, rl_rubout); SET_SPECIAL (VKILL, rl_unix_line_discard);# if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) SET_SPECIAL (VLNEXT, rl_quoted_insert);# endif /* VLNEXT && TERMIOS_TTY_DRIVER */# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) SET_SPECIAL (VWERASE, rl_unix_word_rubout);# endif /* VWERASE && TERMIOS_TTY_DRIVER */}#endif /* !NEW_TTY_DRIVER *//* Set the system's default editing characters to their readline equivalents in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */voidrltty_set_default_bindings (kmap) Keymap kmap;{ TIOTYPE ttybuff; int tty; static int called = 0; tty = fileno (rl_instream); if (get_tty_settings (tty, &ttybuff) == 0) _rl_bind_tty_special_chars (kmap, ttybuff);}/* New public way to set the system default editing chars to their readline equivalents. */voidrl_tty_set_default_bindings (kmap) Keymap kmap;{ rltty_set_default_bindings (kmap);}/* Rebind all of the tty special chars that readline worries about back to self-insert. Call this before saving the current terminal special chars with save_tty_chars(). This only works on POSIX termios or termio systems. */voidrl_tty_unset_default_bindings (kmap) Keymap kmap;{ /* Don't bother before we've saved the tty special chars at least once. */ if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0) return; RESET_SPECIAL (_rl_tty_chars.t_erase); RESET_SPECIAL (_rl_tty_chars.t_kill);# if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) RESET_SPECIAL (_rl_tty_chars.t_lnext);# endif /* VLNEXT && TERMIOS_TTY_DRIVER */# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) RESET_SPECIAL (_rl_tty_chars.t_werase);# endif /* VWERASE && TERMIOS_TTY_DRIVER */}#if defined (HANDLE_SIGNALS)#if defined (NEW_TTY_DRIVER)int_rl_disable_tty_signals (){ return 0;}int_rl_restore_tty_signals (){ return 0;}#elsestatic TIOTYPE sigstty, nosigstty;static int tty_sigs_disabled = 0;int_rl_disable_tty_signals (){ if (tty_sigs_disabled) return 0; if (_get_tty_settings (fileno (rl_instream), &sigstty) < 0) return -1; nosigstty = sigstty; nosigstty.c_lflag &= ~ISIG; nosigstty.c_iflag &= ~IXON; if (_set_tty_settings (fileno (rl_instream), &nosigstty) < 0) return (_set_tty_settings (fileno (rl_instream), &sigstty)); tty_sigs_disabled = 1; return 0;}int_rl_restore_tty_signals (){ int r; if (tty_sigs_disabled == 0) return 0; r = _set_tty_settings (fileno (rl_instream), &sigstty); if (r == 0) tty_sigs_disabled = 0; return r;}#endif /* !NEW_TTY_DRIVER */#endif /* HANDLE_SIGNALS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -