summaryrefslogtreecommitdiff
path: root/src/vte.cc
diff options
context:
space:
mode:
authorChristian Persch <chpe@src.gnome.org>2021-11-27 19:45:07 +0100
committerChristian Persch <chpe@src.gnome.org>2021-11-27 19:45:07 +0100
commit7daaabbc6d8c217b01f94e28c43656fad1170391 (patch)
treedcc6af917ab8f01f723f46f5b9a5c1047c6de007 /src/vte.cc
parentffefea92b97afd334b2f09df7a2ef040598de1c8 (diff)
downloadvte-7daaabbc6d8c217b01f94e28c43656fad1170391.tar.gz
terminal: Add tests for text paste transformation
Move the paste transformation to its own file, and add tests.
Diffstat (limited to 'src/vte.cc')
-rw-r--r--src/vte.cc65
1 files changed, 6 insertions, 59 deletions
diff --git a/src/vte.cc b/src/vte.cc
index fbcb8df4..c326dd54 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -67,6 +67,7 @@
#include <pango/pango.h>
#include "keymap.h"
#include "marshal.h"
+#include "pastify.hh"
#include "vtepty.h"
#include "vtegtk.hh"
#include "cxx-utils.hh"
@@ -5479,65 +5480,11 @@ Terminal::cell_is_selected_vis(vte::grid::column_t vcol,
}
void
-Terminal::widget_clipboard_text_received(std::string_view const& data)
-{
- gchar *paste, *p;
- gsize run;
- unsigned char c;
-
- auto const len = data.size();
- auto text = data.data();
-
- /* Convert newlines to carriage returns, which more software
- * is able to cope with (cough, pico, cough).
- * Filter out control chars except HT, CR (even stricter than xterm).
- * Also filter out C1 controls: U+0080 (0xC2 0x80) - U+009F (0xC2 0x9F). */
- p = paste = (gchar *) g_malloc(len + 1);
- while (p != nullptr && text[0] != '\0') {
- run = strcspn(text, "\x01\x02\x03\x04\x05\x06\x07"
- "\x08\x0A\x0B\x0C\x0E\x0F"
- "\x10\x11\x12\x13\x14\x15\x16\x17"
- "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
- "\x7F\xC2");
- memcpy(p, text, run);
- p += run;
- text += run;
- switch (text[0]) {
- case '\x00':
- break;
- case '\x0A':
- *p = '\x0D';
- p++;
- text++;
- break;
- case '\xC2':
- c = text[1];
- if (c >= 0x80 && c <= 0x9F) {
- /* Skip both bytes of a C1 */
- text += 2;
- } else {
- /* Move along, nothing to see here */
- *p = '\xC2';
- p++;
- text++;
- }
- break;
- default:
- /* Swallow this byte */
- text++;
- break;
- }
- }
-
- bool const bracketed_paste = m_modes_private.XTERM_READLINE_BRACKETED_PASTE();
- // FIXMEchpe can we not hardcode C0 controls here?
- if (bracketed_paste)
- feed_child("\e[200~"sv);
- // FIXMEchpe add a way to avoid the extra string copy done here
- feed_child(paste, p - paste);
- if (bracketed_paste)
- feed_child("\e[201~"sv);
- g_free(paste);
+Terminal::widget_paste(std::string_view const& data)
+{
+ feed_child(vte::terminal::pastify_string(data,
+ m_modes_private.XTERM_READLINE_BRACKETED_PASTE(),
+ false /* C1 */));
}
bool