int gui_key_read_cb (const void *pointer, void *data, int fd) { int ret, i, accept_paste, cancel_paste, text_added_to_buffer, pos; unsigned char buffer[4096]; /* make C compiler happy */ (void) pointer; (void) data; (void) fd; accept_paste = 0; cancel_paste = 0; text_added_to_buffer = 0; ret = read (STDIN_FILENO, buffer, sizeof (buffer)); if (ret == 0) { /* no data on stdin, terminal lost */ if (!weechat_quit) { log_printf (_("Terminal lost, exiting WeeChat...")); (void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL); weechat_quit = 1; } return WEECHAT_RC_OK; } if (ret < 0) return WEECHAT_RC_OK; for (i = 0; i < ret; i++) { /* * add all chars, but ignore a newline ('\r' or '\n') after * another one) */ if ((i == 0) || ((buffer[i] != '\r') && (buffer[i] != '\n')) || ((buffer[i - 1] != '\r') && (buffer[i - 1] != '\n'))) { if (gui_key_paste_pending && (buffer[i] == 25)) { /* ctrl-Y: accept paste */ accept_paste = 1; } else if (gui_key_paste_pending && (buffer[i] == 14)) { /* ctrl-N: cancel paste */ cancel_paste = 1; } else { gui_key_buffer_add (buffer[i]); text_added_to_buffer = 1; } } } if (gui_key_paste_pending) { if (accept_paste) { /* user is OK for pasting text, let's paste! */ gui_key_paste_accept (); } else if (cancel_paste) { /* user doesn't want to paste text: clear whole buffer! */ gui_key_paste_cancel (); } else if (text_added_to_buffer) { /* new text received while asking for paste, update message */ gui_input_paste_pending_signal (); } } else { if (!gui_key_paste_bracketed) { pos = gui_key_buffer_search (0, -1, GUI_KEY_BRACKETED_PASTE_START); if (pos >= 0) { gui_key_buffer_remove (pos, GUI_KEY_BRACKETED_PASTE_LENGTH); gui_key_paste_bracketed_start (); } } if (!gui_key_paste_bracketed) gui_key_paste_check (0); } gui_key_flush ((accept_paste) ? 1 : 0); if (gui_key_paste_bracketed) { pos = gui_key_buffer_search (0, -1, GUI_KEY_BRACKETED_PASTE_END); if (pos >= 0) { /* remove the code for end of bracketed paste (ESC[201~) */ gui_key_buffer_remove (pos, GUI_KEY_BRACKETED_PASTE_LENGTH); /* remove final newline (if needed) */ gui_key_paste_remove_newline (); /* replace tabs by spaces */ gui_key_paste_replace_tabs (); /* stop bracketed mode */ gui_key_paste_bracketed_timer_remove (); gui_key_paste_bracketed_stop (); /* if paste confirmation not displayed, flush buffer now */ if (!gui_key_paste_pending) gui_key_flush (1); } } return WEECHAT_RC_OK; }
int gui_keyboard_read_cb (void *data, int fd) { int ret, i, accept_paste, cancel_paste, text_added_to_buffer, paste_lines; unsigned char buffer[4096]; /* make C compiler happy */ (void) data; (void) fd; accept_paste = 0; cancel_paste = 0; text_added_to_buffer = 0; if (gui_keyboard_paste_pending) { ret = read (STDIN_FILENO, buffer, 1); if (ret == 0) { /* no data on stdin, terminal lost */ log_printf (_("Terminal lost, exiting WeeChat...")); hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL); weechat_quit = 1; return WEECHAT_RC_OK; } if (ret <= 0) return WEECHAT_RC_OK; /* ctrl-Y: accept paste */ if (buffer[0] == 25) accept_paste = 1; /* ctrl-N: cancel paste */ if (buffer[0] == 14) cancel_paste = 1; } else { ret = read (STDIN_FILENO, buffer, sizeof (buffer)); if (ret == 0) { /* no data on stdin, terminal lost */ log_printf (_("Terminal lost, exiting WeeChat...")); hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL); weechat_quit = 1; return WEECHAT_RC_OK; } if (ret < 0) return WEECHAT_RC_OK; for (i = 0; i < ret; i++) { gui_keyboard_buffer_add (buffer[i]); } text_added_to_buffer = 1; } if (gui_keyboard_paste_pending) { /* user is ok for pasting text, let's paste! */ if (accept_paste) gui_keyboard_paste_accept (); /* user doesn't want to paste text: clear whole buffer! */ else if (cancel_paste) gui_keyboard_paste_cancel (); else if (text_added_to_buffer) gui_input_text_changed_modifier_and_signal (gui_current_window->buffer); } else { /* detect user paste or large amount of text if so, ask user what to do */ if (CONFIG_INTEGER(config_look_paste_max_lines) > 0) { paste_lines = gui_keyboard_get_paste_lines (); if (paste_lines > CONFIG_INTEGER(config_look_paste_max_lines)) { gui_keyboard_paste_pending = 1; gui_input_paste_pending_signal (); } } } gui_keyboard_flush (); return WEECHAT_RC_OK; }