* gets_interactive() * * Gets a line of interactive input, using readline if desired. * * prompt: the prompt string to be used * query_buf: buffer containing lines already read in the current command * (query_buf is not modified here, but may be consulted for tab completion) * * The result is a malloc'd string. * * Caller *must* have set up sigint_interrupt_jmp before calling. */
| 64 | * Caller *must* have set up sigint_interrupt_jmp before calling. |
| 65 | */ |
| 66 | char * |
| 67 | gets_interactive(const char *prompt, PQExpBuffer query_buf) |
| 68 | { |
| 69 | #ifdef USE_READLINE |
| 70 | if (useReadline) |
| 71 | { |
| 72 | char *result; |
| 73 | |
| 74 | /* |
| 75 | * Some versions of readline don't notice SIGWINCH signals that arrive |
| 76 | * when not actively reading input. The simplest fix is to always |
| 77 | * re-read the terminal size. This leaves a window for SIGWINCH to be |
| 78 | * missed between here and where readline() enables libreadline's |
| 79 | * signal handler, but that's probably short enough to be ignored. |
| 80 | */ |
| 81 | #ifdef HAVE_RL_RESET_SCREEN_SIZE |
| 82 | rl_reset_screen_size(); |
| 83 | #endif |
| 84 | |
| 85 | /* Make current query_buf available to tab completion callback */ |
| 86 | tab_completion_query_buf = query_buf; |
| 87 | |
| 88 | /* Enable SIGINT to longjmp to sigint_interrupt_jmp */ |
| 89 | sigint_interrupt_enabled = true; |
| 90 | |
| 91 | /* On some platforms, readline is declared as readline(char *) */ |
| 92 | result = readline((char *) prompt); |
| 93 | |
| 94 | /* Disable SIGINT again */ |
| 95 | sigint_interrupt_enabled = false; |
| 96 | |
| 97 | /* Pure neatnik-ism */ |
| 98 | tab_completion_query_buf = NULL; |
| 99 | |
| 100 | return result; |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | fputs(prompt, stdout); |
| 105 | fflush(stdout); |
| 106 | return gets_fromFile(stdin); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /* |
no test coverage detected