Merge pull request #4527 from t-ikegami/Terminal_add_esc_seqs

Add two escape sequences to terminalio.Termial
This commit is contained in:
Scott Shawcroft 2021-04-01 10:38:51 -07:00 committed by GitHub
commit 5425242195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 5 deletions

View File

@ -93,6 +93,41 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
self->cursor_x -= n; self->cursor_x -= n;
} }
} }
if (c == 'J') {
if (n == 2) {
common_hal_displayio_tilegrid_set_top_left(self->tilegrid, 0, 0);
self->cursor_x = self->cursor_y = start_y = 0;
n = 0;
for (uint16_t x = 0; x < self->tilegrid->width_in_tiles; x++) {
for (uint16_t y = 0; y < self->tilegrid->height_in_tiles; y++) {
common_hal_displayio_tilegrid_set_tile(self->tilegrid, x, y, 0);
}
}
}
}
if (c == ';') {
int16_t m = 0;
for (++j; j < 9; j++) {
if ('0' <= i[j] && i[j] <= '9') {
m = m * 10 + (i[j] - '0');
} else {
c = i[j];
break;
}
}
if (c == 'H') {
if (n >= self->tilegrid->height_in_tiles) {
n = self->tilegrid->height_in_tiles - 1;
}
if (m >= self->tilegrid->width_in_tiles) {
m = self->tilegrid->width_in_tiles - 1;
}
n = (n + self->tilegrid->top_left_y) % self->tilegrid->height_in_tiles;
self->cursor_x = m;
self->cursor_y = n;
start_y = self->cursor_y;
}
}
i += j + 1; i += j + 1;
continue; continue;
} }
@ -114,12 +149,14 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
self->cursor_y %= self->tilegrid->height_in_tiles; self->cursor_y %= self->tilegrid->height_in_tiles;
} }
if (self->cursor_y != start_y) { if (self->cursor_y != start_y) {
// clear the new row // clear the new row in case of scroll up
if (self->cursor_y == self->tilegrid->top_left_y) {
for (uint16_t j = 0; j < self->tilegrid->width_in_tiles; j++) { for (uint16_t j = 0; j < self->tilegrid->width_in_tiles; j++) {
common_hal_displayio_tilegrid_set_tile(self->tilegrid, j, self->cursor_y, 0); common_hal_displayio_tilegrid_set_tile(self->tilegrid, j, self->cursor_y, 0);
start_y = self->cursor_y;
} }
common_hal_displayio_tilegrid_set_top_left(self->tilegrid, 0, (start_y + self->tilegrid->height_in_tiles + 1) % self->tilegrid->height_in_tiles); common_hal_displayio_tilegrid_set_top_left(self->tilegrid, 0, (self->cursor_y + self->tilegrid->height_in_tiles + 1) % self->tilegrid->height_in_tiles);
}
start_y = self->cursor_y;
} }
} }
return i - data; return i - data;