void cli_destroy(void) { unsigned int i; if (!cli_event) return; if (cli_rl) { cli_rl = false; rl_replace_line("", 0); rl_crlf(); rl_on_new_line(); rl_redisplay(); rl_message(""); rl_callback_handler_remove(); } sd_event_source_unref(cli_stdin); cli_stdin = NULL; for (i = 0; cli_sigs[i]; ++i) { sd_event_source_unref(cli_sigs[i]); cli_sigs[i] = NULL; } cli_cmds = NULL; sd_bus_detach_event(cli_bus); cli_bus = NULL; sd_event_unref(cli_event); cli_event = NULL; }
static void cli_handler_fn(char *input) { _shl_free_ char *original = input; _shl_strv_free_ char **args = NULL; int r; if (!input) { rl_insert_text("quit"); rl_redisplay(); rl_crlf(); sd_event_exit(cli_event, 0); return; } r = shl_qstr_tokenize(input, &args); if (r < 0) return cli_vENOMEM(); else if (!r) return; add_history(original); r = cli_do(cli_cmds, args, r); if (r != -EAGAIN) return; cli_printf("Command not found\n"); }
void input_start_list(void) /* Leave the currently edited line and make space for listing */ { _rl_move_vert(_rl_vis_botlin); #ifdef HAVE_RL_CRLF rl_crlf(); #endif }
void handle_sigint(int signo) { #ifdef HAVE_ORIG_READLINE rl_reset_line_state(); rl_replace_line("", 0); rl_crlf(); #endif rl_redisplay(); return; }
int rl_print_last_kbd_macro (int count, int ignore) { char *m; if (current_macro == 0) { rl_ding (); return 0; } m = _rl_untranslate_macro_value (current_macro, 1); rl_crlf (); printf ("%s", m); fflush (stdout); rl_crlf (); FREE (m); rl_forced_update_display (); rl_display_fixed = 1; return 0; }
static gboolean signal_handler(GIOChannel *channel, GIOCondition condition, gpointer user_data) { static unsigned int __terminated = 0; struct signalfd_siginfo si; ssize_t result; int fd; if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) { g_main_loop_quit(event_loop); return FALSE; } fd = g_io_channel_unix_get_fd(channel); result = read(fd, &si, sizeof(si)); if (result != sizeof(si)) return FALSE; switch (si.ssi_signo) { case SIGINT: rl_replace_line("", 0); rl_crlf(); rl_on_new_line(); rl_redisplay(); break; case SIGTERM: if (__terminated == 0) { rl_replace_line("", 0); rl_crlf(); g_main_loop_quit(event_loop); } __terminated = 1; break; } return TRUE; }
static void ctrl_c(int signal) { #ifdef USE_READLINE rl_replace_line("", '\0'); rl_crlf(); rl_forced_update_display(); #else LOG(stdout, "\n%s", PROMPT); fflush(stdout); #endif }
static int cli_signal_fn(sd_event_source *source, const struct signalfd_siginfo *ssi, void *data) { if (ssi->ssi_signo == SIGCHLD) { cli_debug("caught SIGCHLD for %d", (int)ssi->ssi_pid); } else if (ssi->ssi_signo == SIGINT) { rl_replace_line("", 0); rl_crlf(); rl_on_new_line(); rl_redisplay(); } else { cli_notice("caught signal %d, exiting..", (int)ssi->ssi_signo); sd_event_exit(cli_event, 0); } return 0; }
int crlf () { return rl_crlf (); }
static void sc_rl_cleanlf(void) { rl_reset_line_state(); rl_crlf(); rl_redisplay(); }
static void cli_mld_crlf (const struct match_list_displayer *displayer) { rl_crlf (); }
//------------------------------------------------------------------------------ static void display_matches(char** matches, int match_count, int max_length) { int i; char** new_matches; CONSOLE_SCREEN_BUFFER_INFO csbi; WORD text_attrib; HANDLE std_out_handle; wchar_t buffer[512]; int show_matches = 2; // The matches need to be processed so needless path information is removed // (this is caused by the \ and / hurdles). max_length = 0; ++match_count; new_matches = (char**)calloc(1, match_count * sizeof(char**)); for (i = 0; i < match_count; ++i) { int len; char* slash = strrchr(matches[i], '\\'); new_matches[i] = (slash != NULL) ? slash + 1 : matches[i]; len = (int)strlen(new_matches[i]); max_length = len > max_length ? len : max_length; } --match_count; std_out_handle = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(std_out_handle, &csbi); // Get the console's current colour settings if (g_match_palette[0] == -1) { // Pick a suitable foreground colour, check fg isn't the same as bg, and set. text_attrib = csbi.wAttributes; text_attrib ^= 0x08; if ((text_attrib & 0xf0) == (text_attrib & 0x0f)) { text_attrib ^= FOREGROUND_INTENSITY; } } else { text_attrib = csbi.wAttributes & 0xf0; text_attrib |= (g_match_palette[0] & 0x0f); } SetConsoleTextAttribute(std_out_handle, text_attrib); // If there's lots of matches, check with the user before displaying them // This matches readline's behaviour, which will get skipped (annoyingly) if ((rl_completion_query_items > 0) && (match_count >= rl_completion_query_items)) { DWORD written; _snwprintf( buffer, sizeof_array(buffer), L"\nDisplay all %d possibilities? (y or n)", match_count ); WriteConsoleW(std_out_handle, buffer, wcslen(buffer), &written, NULL); while (show_matches > 1) { int c = rl_read_key(); switch (c) { case 'y': case 'Y': case ' ': show_matches = 1; break; case 'n': case 'N': case 0x7f: show_matches = 0; break; } } } // Get readline to display the matches. Flush stream so we catch set colours update_screen_size(); if (show_matches > 0) { rl_display_match_list(new_matches, match_count, max_length); } else { rl_crlf(); } fflush(rl_outstream); // Reset console colour back to normal. SetConsoleTextAttribute(std_out_handle, csbi.wAttributes); rl_forced_update_display(); rl_display_fixed = 1; free(new_matches); }
//------------------------------------------------------------------------------ static void display_matches(char** matches, int match_count, int longest) { int i; char** new_matches; CONSOLE_SCREEN_BUFFER_INFO csbi; WORD text_attrib; HANDLE std_out_handle; wchar_t buffer[512]; int show_matches = 2; int match_colour; // Process matches and recalculate the longest match length. new_matches = match_display_filter(matches, match_count); longest = 0; for (i = 0; i < (match_count + 1); ++i) { int len = (int)strlen(new_matches[i]); longest = (len > longest) ? len : longest; } std_out_handle = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(std_out_handle, &csbi); // Get the console's current colour settings match_colour = get_clink_setting_int("match_colour"); if (match_colour == -1) { // Pick a suitable foreground colour, check fg isn't the same as bg, and set. text_attrib = csbi.wAttributes; text_attrib ^= 0x08; if ((text_attrib & 0xf0) == (text_attrib & 0x0f)) { text_attrib ^= FOREGROUND_INTENSITY; } } else { text_attrib = csbi.wAttributes & 0xf0; text_attrib |= (match_colour & 0x0f); } SetConsoleTextAttribute(std_out_handle, text_attrib); // If there's lots of matches, check with the user before displaying them // This matches readline's behaviour, which will get skipped (annoyingly) if ((rl_completion_query_items > 0) && (match_count >= rl_completion_query_items)) { DWORD written; _snwprintf( buffer, sizeof_array(buffer), L"\nDisplay all %d possibilities? (y or n)", match_count ); WriteConsoleW(std_out_handle, buffer, wcslen(buffer), &written, NULL); while (show_matches > 1) { int c = rl_read_key(); switch (c) { case 'y': case 'Y': case ' ': show_matches = 1; break; case 'n': case 'N': case 0x7f: show_matches = 0; break; } } } // Get readline to display the matches. if (show_matches > 0) { // Turn of '/' suffix for directories. RL assumes '/', which isn't the // case, plus clink uses colours instead. int j = _rl_complete_mark_directories; _rl_complete_mark_directories = 0; rl_display_match_list(new_matches, match_count, longest); _rl_complete_mark_directories = j; } else { rl_crlf(); } // Reset console colour back to normal. SetConsoleTextAttribute(std_out_handle, csbi.wAttributes); rl_forced_update_display(); rl_display_fixed = 1; // Tidy up. for (i = 0; i < match_count; ++i) { free(new_matches[i]); } free(new_matches); }