Skip to content

Commit 4179b42

Browse files
author
nicm
committed
Add support for BCE (background colour erase). This makes various escape
sequences (notable EL and ED but also IL, DL, ICH, DCH) create blank cells using the current background colour rather than the default colour. On modern systems BCE doesn't really have many benefits, but most other terminals now support it, some (lazy) applications rely on it, and it is not hard to include now that we have pane background colours anyway. Mostly written by Sean Haugh.
1 parent 1bd08f9 commit 4179b42

File tree

12 files changed

+278
-198
lines changed

12 files changed

+278
-198
lines changed

grid-view.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ grid_view_set_cell(struct grid *gd, u_int px, u_int py,
4747

4848
/* Clear into history. */
4949
void
50-
grid_view_clear_history(struct grid *gd)
50+
grid_view_clear_history(struct grid *gd, u_int bg)
5151
{
5252
struct grid_line*gl;
5353
u_int yy, last;
@@ -56,38 +56,43 @@ grid_view_clear_history(struct grid *gd)
5656
last = 0;
5757
for (yy = 0; yy < gd->sy; yy++) {
5858
gl = &gd->linedata[grid_view_y(gd, yy)];
59-
if (gl->cellsize != 0)
59+
if (gl->cellused != 0)
6060
last = yy + 1;
6161
}
62-
if (last == 0)
62+
if (last == 0) {
63+
grid_view_clear(gd, 0, 0, gd->sx, gd->sy, bg);
6364
return;
65+
}
6466

6567
/* Scroll the lines into the history. */
6668
for (yy = 0; yy < last; yy++) {
67-
grid_collect_history(gd);
68-
grid_scroll_history(gd);
69+
grid_collect_history(gd, bg);
70+
grid_scroll_history(gd, bg);
6971
}
72+
if (last < gd->sy)
73+
grid_view_clear(gd, 0, 0, gd->sx, gd->sy - last, bg);
7074
gd->hscrolled = 0;
7175
}
7276

7377
/* Clear area. */
7478
void
75-
grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
79+
grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny,
80+
u_int bg)
7681
{
7782
px = grid_view_x(gd, px);
7883
py = grid_view_y(gd, py);
7984

80-
grid_clear(gd, px, py, nx, ny);
85+
grid_clear(gd, px, py, nx, ny, bg);
8186
}
8287

8388
/* Scroll region up. */
8489
void
8590
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
8691
{
8792
if (gd->flags & GRID_HISTORY) {
88-
grid_collect_history(gd);
93+
grid_collect_history(gd, 8);
8994
if (rupper == 0 && rlower == gd->sy - 1)
90-
grid_scroll_history(gd);
95+
grid_scroll_history(gd, 8);
9196
else {
9297
rupper = grid_view_y(gd, rupper);
9398
rlower = grid_view_y(gd, rlower);
@@ -96,7 +101,7 @@ grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
96101
} else {
97102
rupper = grid_view_y(gd, rupper);
98103
rlower = grid_view_y(gd, rlower);
99-
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
104+
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, 8);
100105
}
101106
}
102107

@@ -107,26 +112,26 @@ grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
107112
rupper = grid_view_y(gd, rupper);
108113
rlower = grid_view_y(gd, rlower);
109114

110-
grid_move_lines(gd, rupper + 1, rupper, rlower - rupper);
115+
grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, 8);
111116
}
112117

113118
/* Insert lines. */
114119
void
115-
grid_view_insert_lines(struct grid *gd, u_int py, u_int ny)
120+
grid_view_insert_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
116121
{
117122
u_intsy;
118123

119124
py = grid_view_y(gd, py);
120125

121126
sy = grid_view_y(gd, gd->sy);
122127

123-
grid_move_lines(gd, py + ny, py, sy - py - ny);
128+
grid_move_lines(gd, py + ny, py, sy - py - ny, bg);
124129
}
125130

126131
/* Insert lines in region. */
127132
void
128133
grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py,
129-
u_int ny)
134+
u_int ny, u_int bg)
130135
{
131136
u_intny2;
132137

@@ -135,28 +140,28 @@ grid_view_insert_lines_region(struct grid *gd, u_int rlower, u_int py,
135140
py = grid_view_y(gd, py);
136141

137142
ny2 = rlower + 1 - py - ny;
138-
grid_move_lines(gd, rlower + 1 - ny2, py, ny2);
139-
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2);
143+
grid_move_lines(gd, rlower + 1 - ny2, py, ny2, bg);
144+
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);
140145
}
141146

142147
/* Delete lines. */
143148
void
144-
grid_view_delete_lines(struct grid *gd, u_int py, u_int ny)
149+
grid_view_delete_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
145150
{
146151
u_intsy;
147152

148153
py = grid_view_y(gd, py);
149154

150155
sy = grid_view_y(gd, gd->sy);
151156

152-
grid_move_lines(gd, py, py + ny, sy - py - ny);
153-
grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny));
157+
grid_move_lines(gd, py, py + ny, sy - py - ny, bg);
158+
grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny), bg);
154159
}
155160

156161
/* Delete lines inside scroll region. */
157162
void
158163
grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py,
159-
u_int ny)
164+
u_int ny, u_int bg)
160165
{
161166
u_intny2;
162167

@@ -165,13 +170,13 @@ grid_view_delete_lines_region(struct grid *gd, u_int rlower, u_int py,
165170
py = grid_view_y(gd, py);
166171

167172
ny2 = rlower + 1 - py - ny;
168-
grid_move_lines(gd, py, py + ny, ny2);
169-
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2);
173+
grid_move_lines(gd, py, py + ny, ny2, bg);
174+
grid_clear(gd, 0, py + ny2, gd->sx, ny - ny2, bg);
170175
}
171176

172177
/* Insert characters. */
173178
void
174-
grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
179+
grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
175180
{
176181
u_intsx;
177182

@@ -181,14 +186,14 @@ grid_view_insert_cells(struct grid *gd, u_int px, u_int py, u_int nx)
181186
sx = grid_view_x(gd, gd->sx);
182187

183188
if (px == sx - 1)
184-
grid_clear(gd, px, py, 1, 1);
189+
grid_clear(gd, px, py, 1, 1, bg);
185190
else
186-
grid_move_cells(gd, px + nx, px, py, sx - px - nx);
191+
grid_move_cells(gd, px + nx, px, py, sx - px - nx, bg);
187192
}
188193

189194
/* Delete characters. */
190195
void
191-
grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
196+
grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
192197
{
193198
u_intsx;
194199

@@ -197,8 +202,8 @@ grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx)
197202

198203
sx = grid_view_x(gd, gd->sx);
199204

200-
grid_move_cells(gd, px, px + nx, py, sx - px - nx);
201-
grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1);
205+
grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg);
206+
grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1, bg);
202207
}
203208

204209
/* Convert cells into a string. */

0 commit comments

Comments
 (0)