diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-06-17 17:33:10 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-06-17 17:33:10 +0000 |
| commit | 4585df532c3c34ef86a94fda6d53a3f6df5244a8 (patch) | |
| tree | 547af356258e890b35c864ed6a322e31a4930951 | |
| parent | wip: vt parsing (diff) | |
wip: vt parsing: break out grid operating functions
| -rw-r--r-- | csi.c | 34 | ||||
| -rw-r--r-- | grid.c | 34 | ||||
| -rw-r--r-- | grid.h | 8 | ||||
| -rw-r--r-- | meson.build | 1 | ||||
| -rw-r--r-- | vt.c | 15 |
5 files changed, 56 insertions, 36 deletions
@@ -8,6 +8,7 @@ #define LOG_MODULE "csi" #define LOG_ENABLE_DBG 1 #include "log.h" +#include "grid.h" static bool csi_sgr(struct terminal *term) @@ -74,21 +75,6 @@ csi_sgr(struct terminal *term) return true; } -static bool -erase(struct terminal *term, int start, int end) -{ - for (int i = start; i < end; i++) { - struct cell *cell = &term->grid.cells[i]; - memset(cell, 0, sizeof(*cell)); - cell->attrs.foreground = term->grid.foreground; - cell->attrs.background = term->grid.background; - cell->dirty = true; - term->grid.dirty = true; - } - - return true; -} - bool csi_dispatch(struct terminal *term, uint8_t final) { @@ -112,7 +98,8 @@ csi_dispatch(struct terminal *term, uint8_t final) assert(term->vt.params.idx == 0); int start = term->grid.cursor / term->grid.cols * term->grid.cols; int end = term->grid.cols * term->grid.rows; - return erase(term, start, end); + grid_erase(&term->grid, start, end); + return true; } case 'K': { @@ -122,26 +109,19 @@ csi_dispatch(struct terminal *term, uint8_t final) assert(start <= end); assert((end + 1) % term->grid.cols == 0); - return erase(term, start, end); + grid_erase(&term->grid, start, end); + return true; } case 'C': { int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1; - int new_cursor = term->grid.cursor + count; - term->grid.cells[term->grid.cursor].dirty = true; - term->grid.cells[new_cursor].dirty = true; - term->grid.cursor = new_cursor; - term->grid.dirty = true; + grid_cursor_move(&term->grid, count); return true; } case 'D': { int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1; - int new_cursor = term->grid.cursor - count; - term->grid.cells[term->grid.cursor].dirty = true; - term->grid.cells[new_cursor].dirty = true; - term->grid.cursor = new_cursor; - term->grid.dirty = true; + grid_cursor_move(&term->grid, -count); return true; } @@ -0,0 +1,34 @@ +#include "grid.h" + +#include <string.h> + +void +grid_erase(struct grid *grid, int start, int end) +{ + for (int i = start; i < end; i++) { + struct cell *cell = &grid->cells[i]; + memset(cell, 0, sizeof(*cell)); + + cell->attrs.foreground = grid->foreground; + cell->attrs.background = grid->background; + + cell->dirty = true; + grid->dirty = true; + } +} + +void +grid_cursor_move(struct grid *grid, int cols) +{ + int new_cursor = grid->cursor + cols; + grid->cells[grid->cursor].dirty = true; + grid->cells[new_cursor].dirty = true; + grid->cursor = new_cursor; + grid->dirty = true; +} + +void +grid_cursor_to(struct grid *grid, int pos) +{ + grid_cursor_move(grid, pos - grid->cursor); +} @@ -0,0 +1,8 @@ +#pragma once + +#include "terminal.h" + +void grid_erase(struct grid *grid, int start, int end); + +void grid_cursor_to(struct grid *grid, int pos); +void grid_cursor_move(struct grid *grid, int cols); diff --git a/meson.build b/meson.build index f1953050..249c5f43 100644 --- a/meson.build +++ b/meson.build @@ -59,6 +59,7 @@ executable( 'f00ter', 'csi.c', 'csi.h', 'font.c', 'font.h', + 'grid.c', 'grid.h', 'log.c', 'log.h', 'main.c', 'osc.c', 'osc.h', @@ -9,6 +9,7 @@ #include "log.h" #include "csi.h" #include "osc.h" +#include "grid.h" /* https://vt100.net/emu/dec_ansi_parser */ @@ -157,17 +158,13 @@ action(struct terminal *term, enum action action, uint8_t c) LOG_DBG("execute: 0x%02x", c); switch (c) { case '\r': - term->grid.cells[term->grid.cursor].dirty = true; - term->grid.cursor = term->grid.cursor / term->grid.cols * term->grid.cols; - term->grid.cells[term->grid.cursor].dirty = true; - term->grid.dirty = true; + grid_cursor_to( + &term->grid, + term->grid.cursor / term->grid.cols * term->grid.cols); break; case '\b': - term->grid.cells[term->grid.cursor].dirty = true; - term->grid.cursor--; - term->grid.cells[term->grid.cursor].dirty = true; - term->grid.dirty = true; + grid_cursor_move(&term->grid, -1); break; } @@ -197,7 +194,7 @@ action(struct terminal *term, enum action action, uint8_t c) cell->attrs = term->vt.attrs; - term->grid.cells[++term->grid.cursor].dirty = true; + grid_cursor_move(&term->grid, 1); term->grid.dirty = true; break; } |
