}
}
-__attribute__((noinline))
static void mtty_row_roll(mtty_row_t *start, mtty_row_t *end, int count)
{
int n = end - start;
mtty_row_set(rt->curs_row, 0, rt->cols, 0);
}
+__attribute__((const))
static uint16_t build_attrs(unsigned curattrs)
{
return ((curattrs & ~A_COLOR) | COLOR_PAIR(curattrs & 0xff))
/* interprets an 'erase display' (ED) escape sequence */
static void interpret_csi_ED(madtty_t *rt, int param[], int pcount)
{
- int r;
- int start_row, start_col, end_row, end_col;
+ mtty_row_t *row, *start, *end;
+ attr_t attr = build_attrs(rt->curattrs);
/* decide range */
if (pcount && param[0] == 2) {
- start_row = 0;
- start_col = 0;
- end_row = rt->rows - 1;
- end_col = rt->cols - 1;
+ start = rt->lines;
+ end = rt->lines + rt->rows;
} else
if (pcount && param[0] == 1) {
- start_row = 0;
- start_col = 0;
- end_row = rt->curs_row - rt->lines;
- end_col = rt->curs_col;
+ start = rt->lines;
+ end = rt->curs_row;
+ mtty_row_set(rt->curs_row, 0, rt->curs_col + 1, attr);
} else {
- start_row = rt->curs_row - rt->lines;
- start_col = rt->curs_col;
- end_row = rt->rows - 1;
- end_col = rt->cols - 1;
+ mtty_row_set(rt->curs_row, rt->curs_col,
+ rt->cols - rt->curs_col, attr);
+ start = rt->curs_row + 1;
+ end = rt->lines + rt->rows;
}
- /* clean range */
- mtty_row_set(rt->lines + start_row, start_col, rt->cols - start_col,
- build_attrs(rt->curattrs));
- for (r = start_row + 1; r < end_row; r++) {
- mtty_row_set(rt->lines + r, 0, rt->cols, build_attrs(rt->curattrs));
+ for (row = start; row < end; row++) {
+ mtty_row_set(row, 0, rt->cols, attr);
}
- mtty_row_set(rt->lines + end_row, 0, end_col + 1,
- build_attrs(rt->curattrs));
}
/* interprets a 'move cursor' (CUP) escape sequence */
int n = (pcount && param[0] > 0) ? param[0] : 1;
int i;
+ if (rt->curs_col + n > rt->cols) {
+ n = rt->cols - rt->curs_col;
+ }
+
for (i = rt->cols - 1; i >= rt->curs_col + n; i--) {
row->text[i] = row->text[i - n];
row->attr[i] = row->attr[i - n];
int n = (pcount && param[0] > 0) ? param[0] : 1;
int i;
- for (i = rt->curs_col; i < rt->cols; i++) {
- if (i + n < rt->cols) {
- row->text[i] = row->text[i + n];
- row->attr[i] = row->attr[i + n];
- } else {
- row->text[i] = 0;
- row->attr[i] = build_attrs(rt->curattrs);
- }
+ if (rt->curs_col + n > rt->cols) {
+ n = rt->cols - rt->curs_col;
+ }
+
+ for (i = rt->curs_col; i < rt->cols - n; i++) {
+ row->text[i] = row->text[i + n];
+ row->attr[i] = row->attr[i + n];
}
+
+ mtty_row_set(row, rt->cols - n, n, build_attrs(rt->curattrs));
}
/* Interpret an 'insert line' sequence (IL) */
}
} else {
mtty_row_roll(rt->curs_row, rt->scroll_bot, -n);
-
for (mtty_row_t *row = rt->scroll_bot - n; row < rt->scroll_bot; row++) {
mtty_row_set(row, 0, rt->cols, build_attrs(rt->curattrs));
}
case 2:
new_top = param[0] - 1;
- new_bot = param[1] - 1;
+ new_bot = param[1];
/* clamp to bounds */
if (new_top < 0)