Skip to content

Instantly share code, notes, and snippets.

@Osse
Created July 2, 2012 15:04
Show Gist options
  • Save Osse/3033684 to your computer and use it in GitHub Desktop.
Save Osse/3033684 to your computer and use it in GitHub Desktop.
Patch to add replacement of linebreaks with spaces
diff --git a/src/gui/curses/gui-curses-key.c b/src/gui/curses/gui-curses-key.c
index 92393ac..db1fe59 100644
--- a/src/gui/curses/gui-curses-key.c
+++ b/src/gui/curses/gui-curses-key.c
@@ -487,7 +487,7 @@ gui_key_flush (int paste)
int
gui_key_read_cb (void *data, int fd)
{
- int ret, i, accept_paste, cancel_paste, text_added_to_buffer, pos;
+ int ret, i, accept_paste, cancel_paste, replace_paste, text_added_to_buffer, pos;
unsigned char buffer[4096];
/* make C compiler happy */
@@ -496,6 +496,7 @@ gui_key_read_cb (void *data, int fd)
accept_paste = 0;
cancel_paste = 0;
+ replace_paste = 0;
text_added_to_buffer = 0;
ret = read (STDIN_FILENO, buffer, sizeof (buffer));
@@ -532,6 +533,11 @@ gui_key_read_cb (void *data, int fd)
/* ctrl-N: cancel paste */
cancel_paste = 1;
}
+ else if (buffer[i] == 18)
+ {
+ /* ctrl-R: replace paste */
+ replace_paste = 1;
+ }
}
else
{
@@ -553,6 +559,11 @@ gui_key_read_cb (void *data, int fd)
/* user doesn't want to paste text: clear whole buffer! */
gui_key_paste_cancel ();
}
+ else if (replace_paste)
+ {
+ /* user wants to paste text with replacement: let's replace! */
+ gui_key_paste_replace ();
+ }
else if (text_added_to_buffer)
{
/* new text received while asking for paste, update message */
diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c
index 6cd68b4..a2e0dea 100644
--- a/src/gui/gui-bar-item.c
+++ b/src/gui/gui-bar-item.c
@@ -601,8 +601,8 @@ gui_bar_item_default_input_paste (void *data, struct t_gui_bar_item *item,
lines = gui_key_get_paste_lines ();
snprintf (buf, sizeof (buf),
- NG_("%sPaste %d line ? [ctrl-Y] Yes [ctrl-N] No",
- "%sPaste %d lines ? [ctrl-Y] Yes [ctrl-N] No",
+ NG_("%sPaste %d line ? [ctrl-Y] Yes [ctrl-N] No [ctrl-R] Replace linebreaks with spaces",
+ "%sPaste %d lines ? [ctrl-Y] Yes [ctrl-N] No [ctrl-R] Replace linebreaks with spaces",
lines),
gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_input_actions))),
lines);
diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c
index 8274b25..b497428 100644
--- a/src/gui/gui-key.c
+++ b/src/gui/gui-key.c
@@ -1678,6 +1678,30 @@ gui_key_paste_cancel ()
}
/*
+ * gui_key_paste_replace: Replace newlines in paste from user
+ */
+
+void
+gui_key_paste_replace ()
+{
+ /*
+ * Replace newlines with space then proceed to
+ * paste the contents
+ */
+ if ((gui_key_get_paste_lines () > 1)
+ && (gui_key_buffer_size > 0))
+ {
+ int i;
+ for (i = 0; i < gui_key_buffer_size; i++)
+ {
+ if (gui_key_buffer[i] == '\n' || gui_key_buffer[i] == '\r')
+ gui_key_buffer[i] = ' ';
+ }
+ }
+ gui_key_paste_accept ();
+}
+
+/*
* gui_key_end: end keyboard (free some data)
*/
diff --git a/src/gui/gui-key.h b/src/gui/gui-key.h
index 78a9e8d..b1a8485 100644
--- a/src/gui/gui-key.h
+++ b/src/gui/gui-key.h
@@ -129,6 +129,7 @@ extern void gui_key_paste_bracketed_start ();
extern void gui_key_paste_bracketed_stop ();
extern void gui_key_paste_accept ();
extern void gui_key_paste_cancel ();
+extern void gui_key_paste_replace ();
extern void gui_key_end ();
extern struct t_hdata *gui_key_hdata_key_cb (void *data,
const char *hdata_name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment