commit c733a52

uint  ·  2026-05-14 18:48:11 +0000 UTC
parent a31a447
add csi insert and delete chars
1 files changed,  +44, -0
+44, -0
 1@@ -9,6 +9,8 @@
 2 
 3 static int csi_arg(Term* t, int i, int fallback);
 4 static void alt_screen(Term* t, Caret* c, bool on);
 5+static void chars_insert(Term* t, Caret* c, int n);
 6+static void chars_delete(Term* t, Caret* c, int n);
 7 static void csi_dispatch(Term* t, Caret* c, unsigned char ch);
 8 static void csi_reset(Term* t);
 9 static void erase_display(Term* t, Caret* c);
10@@ -65,11 +67,48 @@ static void alt_screen(Term* t, Caret* c, bool on)
11 	term_damage_all(t);
12 }
13 
14+/** TODO
15+ */
16+static void chars_insert(Term* t, Caret* c, int n)
17+{
18+	int cols = t->cols - c->x;
19+	Rune* line = &RUNE(t, 0, c->y);
20+
21+	if (n > cols)
22+		n = cols;
23+	memmove(&line[c->x + n], &line[c->x], sizeof(Rune) * (cols - n));
24+	for (int x = c->x; x < c->x + n; x++)
25+		reset_rune(t, x, c->y);
26+	for (int x = c->x + n; x < t->cols; x++)
27+		RUNE(t, x, c->y).dmg = true;
28+}
29+
30+/** TODO
31+ */
32+static void chars_delete(Term* t, Caret* c, int n)
33+{
34+	int cols = t->cols - c->x;
35+	Rune* line = &RUNE(t, 0, c->y);
36+
37+	if (n > cols)
38+		n = cols;
39+	memmove(&line[c->x], &line[c->x + n], sizeof(Rune) * (cols - n));
40+	for (int x = t->cols - n; x < t->cols; x++)
41+		reset_rune(t, x, c->y);
42+	for (int x = c->x; x < t->cols - n; x++)
43+		RUNE(t, x, c->y).dmg = true;
44+}
45+
46 /** TODO
47  */
48 static void csi_dispatch(Term* t, Caret* c, unsigned char ch)
49 {
50 	switch (ch) {
51+	case '@': /* ICH - Insert Character */
52+		t->wrapnext = false;
53+		chars_insert(t, c, csi_arg(t, 0, 1));
54+		break;
55+
56 	case 'H': /* CUP - Cursor Position - ESC[row;colH */
57 	case 'f': { /* HVP - Horizontal and Vertical Postion - ESC[row;colf */
58 		t->wrapnext = false;
59@@ -98,6 +137,11 @@ static void csi_dispatch(Term* t, Caret* c, unsigned char ch)
60 		erase_line(t, c);
61 		break;
62 
63+	case 'P': /* DCH - Delete Character */
64+		t->wrapnext = false;
65+		chars_delete(t, c, csi_arg(t, 0, 1));
66+		break;
67+
68 	case 'X': { /* ECH - Erase Character */
69 		int n = csi_arg(t, 0, 1);
70 		for (int x = c->x; x < c->x + n && x < t->cols; x++)