static char *read_input_line (Slsh_Readline_Type *sri, char *prompt, int noecho) { char *line; if (Use_Readline == 0) return read_with_no_readline (prompt, noecho); #if SYSTEM_SUPPORTS_SIGNALS init_tty (); #endif #if USE_GNU_READLINE (void) sri; if (noecho == 0) rl_redisplay_function = rl_redisplay; else { /* FIXME: What is the proper way to implement this in GNU readline? */ (void) fputs (prompt, stdout); (void) fflush (stdout); rl_redisplay_function = redisplay_dummy; } line = readline (prompt); rl_redisplay_function = rl_redisplay; #else SLtt_get_screen_size (); SLrline_set_display_width (sri->rli, SLtt_Screen_Cols); (void) add_sigwinch_handlers (); Active_Rline_Info = sri; (void) SLrline_set_echo (sri->rli, (noecho == 0)); line = SLrline_read_line (sri->rli, prompt, NULL); Active_Rline_Info = NULL; #endif #if SYSTEM_SUPPORTS_SIGNALS reset_tty (); #endif if (sri->output_newline) fputs ("\r\n", stdout); fflush (stdout); return line; }
static void init_tty (void) { int abort_char = 3; TTY_Inited++; if (TTY_Inited > 1) return; # if SYSTEM_SUPPORTS_SIGNALS SLsig_block_signals (); SLang_TT_Read_FD = fileno (stdin); init_sigtstp (); # endif # ifdef REAL_UNIX_SYSTEM abort_char = -1; /* determine from tty */ # endif if (-1 == SLang_init_tty (abort_char, 1, 1)) /* opost was 0 */ { # if SYSTEM_SUPPORTS_SIGNALS deinit_sigtstp (); SLsig_unblock_signals (); # endif SLang_exit_error ("Error initializing terminal."); } # ifdef REAL_UNIX_SYSTEM SLang_getkey_intr_hook = getkey_intr_hook; # endif (void) add_sigwinch_handlers (); SLtt_get_screen_size (); # if SYSTEM_SUPPORTS_SIGNALS SLtty_set_suspend_state (1); SLsig_unblock_signals (); # endif }
static void init_tty (void) /*{{{*/ { #ifdef HAVE_GNU_READLINE if (Use_SLang_Readline == 0) { SLsig_block_signals (); last_sig_sigint = SLsignal (SIGINT, gnu_rl_sigint_handler); last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp); SLsig_unblock_signals (); return; } #endif if (TTY_Inited) return; TTY_Inited++; SLsig_block_signals (); SLang_TT_Read_FD = fileno (stdin); last_sig_sigtstp = SLsignal (SIGTSTP, sig_sigtstp); if (-1 == SLang_init_tty (-1, 1, 0)) { SLsignal (SIGTSTP, last_sig_sigtstp); SLsig_unblock_signals (); fprintf (stderr, "Error initializing terminal."); exit (EXIT_FAILURE); } SLang_getkey_intr_hook = getkey_intr_hook; (void) add_sigwinch_handlers (); SLtt_get_screen_size (); SLtty_set_suspend_state (1); SLsig_unblock_signals (); }
static char *read_input_line (SLang_RLine_Info_Type *rline, char *prompt, int noecho) { char *line; #ifdef REAL_UNIX_SYSTEM int stdin_is_noecho = 0; #endif if (Use_Readline == 0) { char buf[1024]; char *b; fprintf (stdout, "%s", prompt); fflush (stdout); if (noecho) { #ifdef REAL_UNIX_SYSTEM if (isatty (fileno(stdin))) { (void) SLsystem ("stty -echo"); /* yuk */ stdin_is_noecho = 1; } #endif } line = buf; while (NULL == fgets (buf, sizeof (buf), stdin)) { #ifdef EINTR if (errno == EINTR) { if (-1 == SLang_handle_interrupt ()) { line = NULL; break; } continue; } #endif line = NULL; break; } #ifdef REAL_UNIX_SYSTEM if (stdin_is_noecho) (void) SLsystem ("stty echo"); #endif if (line == NULL) return NULL; /* Remove the final newline */ b = line; while (*b && (*b != '\n')) b++; *b = 0; return SLmake_string (line); } #if SYSTEM_SUPPORTS_SIGNALS init_tty (); #endif #if USE_GNU_READLINE (void) rline; if (noecho == 0) rl_redisplay_function = rl_redisplay; else { /* FIXME: What is the proper way to implement this in GNU readline? */ (void) fputs (prompt, stdout); (void) fflush (stdout); rl_redisplay_function = redisplay_dummy; } line = readline (prompt); rl_redisplay_function = rl_redisplay; #else SLtt_get_screen_size (); SLrline_set_display_width (rline, SLtt_Screen_Cols); (void) add_sigwinch_handlers (); Active_Rline_Info = rline; (void) SLrline_set_echo (rline, (noecho == 0)); line = SLrline_read_line (rline, prompt, NULL); Active_Rline_Info = NULL; #endif #if SYSTEM_SUPPORTS_SIGNALS reset_tty (); #else fputs ("\r\n", stdout); fflush (stdout); #endif return line; }