-
Notifications
You must be signed in to change notification settings - Fork 0
/
st.c.rej
137 lines (125 loc) · 3.01 KB
/
st.c.rej
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--- st.c
+++ st.c
@@ -1435,89 +1598,93 @@ tsetchar(Rune u, const Glyph *attr, int x, int y)
} else if (term.line[y][x].mode & ATTR_WDUMMY) {
term.line[y][x-1].u = ' ';
term.line[y][x-1].mode &= ~ATTR_WIDE;
- }
+ }
term.dirty[y] = 1;
term.line[y][x] = *attr;
term.line[y][x].u = u;
+ term.line[y][x].mode |= ATTR_SET;
}
void
-tclearregion(int x1, int y1, int x2, int y2)
+tclearglyph(Glyph *gp, int usecurattr)
{
- int x, y, temp;
- Glyph *gp;
+ if (usecurattr) {
+ gp->fg = term.c.attr.fg;
+ gp->bg = term.c.attr.bg;
+ } else {
+ gp->fg = defaultfg;
+ gp->bg = defaultbg;
+ }
+ gp->mode = ATTR_NULL;
+ gp->u = ' ';
+}
- if (x1 > x2)
- temp = x1, x1 = x2, x2 = temp;
- if (y1 > y2)
- temp = y1, y1 = y2, y2 = temp;
+void
+tclearregion(int x1, int y1, int x2, int y2, int usecurattr)
+{
+ int x, y;
- LIMIT(x1, 0, term.col-1);
- LIMIT(x2, 0, term.col-1);
- LIMIT(y1, 0, term.row-1);
- LIMIT(y2, 0, term.row-1);
+ /* regionselected() takes relative coordinates */
+ if (regionselected(x1+term.scr, y1+term.scr, x2+term.scr, y2+term.scr))
+ selremove();
for (y = y1; y <= y2; y++) {
term.dirty[y] = 1;
- for (x = x1; x <= x2; x++) {
- gp = &term.line[y][x];
- if (selected(x, y))
- selclear();
- gp->fg = term.c.attr.fg;
- gp->bg = term.c.attr.bg;
- gp->mode = 0;
- gp->u = ' ';
- }
+ for (x = x1; x <= x2; x++)
+ tclearglyph(&term.line[y][x], usecurattr);
}
}
void
tdeletechar(int n)
{
- int dst, src, size;
- Glyph *line;
-
- LIMIT(n, 0, term.col - term.c.x);
+ int src, dst, size;
+ Line line;
+ if (n <= 0)
+ return;
dst = term.c.x;
- src = term.c.x + n;
+ src = MIN(term.c.x + n, term.col);
size = term.col - src;
- line = term.line[term.c.y];
-
- memmove(&line[dst], &line[src], size * sizeof(Glyph));
- tclearregion(term.col-n, term.c.y, term.col-1, term.c.y);
+ if (size > 0) { /* otherwise src would point beyond the array
+ https://stackoverflow.com/questions/29844298 */
+ line = term.line[term.c.y];
+ memmove(&line[dst], &line[src], size * sizeof(Glyph));
+ }
+ tclearregion(dst + size, term.c.y, term.col - 1, term.c.y, 1);
}
void
tinsertblank(int n)
{
- int dst, src, size;
- Glyph *line;
+ int src, dst, size;
+ Line line;
- LIMIT(n, 0, term.col - term.c.x);
-
- dst = term.c.x + n;
+ if (n <= 0)
+ return;
+ dst = MIN(term.c.x + n, term.col);
src = term.c.x;
size = term.col - dst;
- line = term.line[term.c.y];
-
- memmove(&line[dst], &line[src], size * sizeof(Glyph));
- tclearregion(src, term.c.y, dst - 1, term.c.y);
+ if (size > 0) { /* otherwise dst would point beyond the array */
+ line = term.line[term.c.y];
+ memmove(&line[dst], &line[src], size * sizeof(Glyph));
+ }
+ tclearregion(src, term.c.y, dst - 1, term.c.y, 1);
}
void
tinsertblankline(int n)
{
if (BETWEEN(term.c.y, term.top, term.bot))
- tscrolldown(term.c.y, n, 0);
+ tscrolldown(term.c.y, n);
}
void
tdeleteline(int n)
{
if (BETWEEN(term.c.y, term.top, term.bot))
- tscrollup(term.c.y, n, 0);
+ tscrollup(term.c.y, term.bot, n, SCROLL_NOSAVEHIST);
}
int32_t