commit d647190
uint
·
2026-07-31 18:36:02 +0000 UTC
parent 0337661
add pasting from clipboard
4 files changed,
+42,
-4
+14,
-1
1@@ -9,7 +9,7 @@ static const char font_path[] = "monospace.bdf";
2
3 static const int win_width = 80; /* in columns */
4 static const int win_height = 24; /* in rows */
5-static const char win_title[] = "cterm";
6+static const char win_title[] = "cterm";
7 static const int win_fps = 60;
8
9 static const int pad_x = 8;
10@@ -18,6 +18,19 @@ static const int pad_y = 8;
11 static const char* const shell = NULL; /* NULL uses $SHELL */
12 static const char term_name[] = "vt100";
13
14+#define CTRL_DOWN (win->key_syms[MAUS_KEY_CONTROL_L] || win->key_syms[MAUS_KEY_CONTROL_R])
15+#define SHIFT_DOWN (win->key_syms[MAUS_KEY_SHIFT_L] || win->key_syms[MAUS_KEY_SHIFT_R])
16+
17+#define BIND_COPY (CTRL_DOWN && SHIFT_DOWN && \
18+ (ev->key.key == MAUS_KEY_C || ev->key.key == MAUS_KEY_C_UP))
19+
20+#define BIND_PASTE (CTRL_DOWN && SHIFT_DOWN && \
21+ (ev->key.key == MAUS_KEY_V || ev->key.key == MAUS_KEY_V_UP))
22+
23+#define BIND_RELOAD_FONT (win->key_syms[MAUS_KEY_ALT_R] && \
24+ (ev->key.key == MAUS_KEY_R || \
25+ ev->key.key == MAUS_KEY_R_UP))
26+
27 /* AARRGGBB */
28 static const uint32_t default_fg = 0xffffffff;
29 static const uint32_t default_bg = 0xff000000;
+1,
-0
1@@ -58,6 +58,7 @@ typedef struct {
2 int charset_target;
3 bool wrapnext;
4 bool cursor_visible;
5+ bool bracketed_paste;
6 int csi_params[CSI_PARAMS_MAX];
7 int csi_idx;
8 char utf8[4];
+25,
-3
1@@ -6,6 +6,7 @@
2 #include <stdbool.h>
3 #include <stdint.h>
4 #include <stdlib.h>
5+#include <string.h>
6 #include <sys/ioctl.h>
7 #include <time.h>
8 #ifdef __linux__
9@@ -73,11 +74,31 @@ static bool handle_key(const MausEvent* ev)
10 if (ev->type != MAUS_EV_KEY || !ev->key.pressed)
11 return false;
12
13- if (win->key_syms[MAUS_KEY_ALT_R] &&
14- (ev->key.key == MAUS_KEY_R ||
15- ev->key.key == MAUS_KEY_R_UP))
16+ if (BIND_RELOAD_FONT)
17 return reload_font();
18
19+ if (BIND_PASTE) {
20+ char* text = maus_clipboard_get_text(win);
21+
22+ if (text && text[0] != '\0') {
23+ /* bracketed paste mode on */
24+ if (term.bracketed_paste)
25+ ptywrite("\033[200~", 6);
26+
27+ for (char* p = text; *p; p++) {
28+ /* replace newlines with carriage returns */
29+ char ch = (*p == '\n') ? '\r' : *p;
30+ ptywrite(&ch, 1);
31+ }
32+
33+ /* bracketed paste mode off */
34+ if (term.bracketed_paste)
35+ ptywrite("\033[201~", 6);
36+ }
37+
38+ return true;
39+ }
40+
41 switch(ev->key.key) {
42 case MAUS_KEY_ENTER:
43 case MAUS_KEY_KP_ENTER: ptywrite("\r", 1); break;
44@@ -323,6 +344,7 @@ static void run(void)
45
46 if (redraw_all) {
47 draw_clear(win->bfb, win->stride, winh, rgba(0, 0, 0, 255));
48+ term_damage_all(&term);
49 }
50
51 for (int y = 0; y < term.rows; y++) {
+2,
-0
1@@ -255,6 +255,8 @@ static void csi_dispatch(Term* t, Caret* c, unsigned char ch)
2 int p = t->csi_params[i];
3 if (p == 25)
4 t->cursor_visible = on;
5+ if (p == 2004)
6+ t->bracketed_paste = on;
7 if (p == 1048) {
8 if (on)
9 t->saved = *c;