mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-30 11:10:23 -04:00
wip: vt parsing: break out grid operating functions
This commit is contained in:
parent
6d5f5b9f7a
commit
4585df532c
5 changed files with 56 additions and 36 deletions
34
csi.c
34
csi.c
|
|
@ -8,6 +8,7 @@
|
||||||
#define LOG_MODULE "csi"
|
#define LOG_MODULE "csi"
|
||||||
#define LOG_ENABLE_DBG 1
|
#define LOG_ENABLE_DBG 1
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "grid.h"
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
csi_sgr(struct terminal *term)
|
csi_sgr(struct terminal *term)
|
||||||
|
|
@ -74,21 +75,6 @@ csi_sgr(struct terminal *term)
|
||||||
return true;
|
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
|
bool
|
||||||
csi_dispatch(struct terminal *term, uint8_t final)
|
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);
|
assert(term->vt.params.idx == 0);
|
||||||
int start = term->grid.cursor / term->grid.cols * term->grid.cols;
|
int start = term->grid.cursor / term->grid.cols * term->grid.cols;
|
||||||
int end = term->grid.cols * term->grid.rows;
|
int end = term->grid.cols * term->grid.rows;
|
||||||
return erase(term, start, end);
|
grid_erase(&term->grid, start, end);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'K': {
|
case 'K': {
|
||||||
|
|
@ -122,26 +109,19 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
assert(start <= end);
|
assert(start <= end);
|
||||||
assert((end + 1) % term->grid.cols == 0);
|
assert((end + 1) % term->grid.cols == 0);
|
||||||
|
|
||||||
return erase(term, start, end);
|
grid_erase(&term->grid, start, end);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'C': {
|
case 'C': {
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
||||||
int new_cursor = term->grid.cursor + count;
|
grid_cursor_move(&term->grid, 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;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'D': {
|
case 'D': {
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
||||||
int new_cursor = term->grid.cursor - count;
|
grid_cursor_move(&term->grid, -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;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
34
grid.c
Normal file
34
grid.c
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
8
grid.h
Normal file
8
grid.h
Normal file
|
|
@ -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);
|
||||||
|
|
@ -59,6 +59,7 @@ executable(
|
||||||
'f00ter',
|
'f00ter',
|
||||||
'csi.c', 'csi.h',
|
'csi.c', 'csi.h',
|
||||||
'font.c', 'font.h',
|
'font.c', 'font.h',
|
||||||
|
'grid.c', 'grid.h',
|
||||||
'log.c', 'log.h',
|
'log.c', 'log.h',
|
||||||
'main.c',
|
'main.c',
|
||||||
'osc.c', 'osc.h',
|
'osc.c', 'osc.h',
|
||||||
|
|
|
||||||
15
vt.c
15
vt.c
|
|
@ -9,6 +9,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "csi.h"
|
#include "csi.h"
|
||||||
#include "osc.h"
|
#include "osc.h"
|
||||||
|
#include "grid.h"
|
||||||
|
|
||||||
/* https://vt100.net/emu/dec_ansi_parser */
|
/* 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);
|
LOG_DBG("execute: 0x%02x", c);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\r':
|
case '\r':
|
||||||
term->grid.cells[term->grid.cursor].dirty = true;
|
grid_cursor_to(
|
||||||
term->grid.cursor = term->grid.cursor / term->grid.cols * term->grid.cols;
|
&term->grid,
|
||||||
term->grid.cells[term->grid.cursor].dirty = true;
|
term->grid.cursor / term->grid.cols * term->grid.cols);
|
||||||
term->grid.dirty = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\b':
|
case '\b':
|
||||||
term->grid.cells[term->grid.cursor].dirty = true;
|
grid_cursor_move(&term->grid, -1);
|
||||||
term->grid.cursor--;
|
|
||||||
term->grid.cells[term->grid.cursor].dirty = true;
|
|
||||||
term->grid.dirty = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,7 +194,7 @@ action(struct terminal *term, enum action action, uint8_t c)
|
||||||
|
|
||||||
cell->attrs = term->vt.attrs;
|
cell->attrs = term->vt.attrs;
|
||||||
|
|
||||||
term->grid.cells[++term->grid.cursor].dirty = true;
|
grid_cursor_move(&term->grid, 1);
|
||||||
term->grid.dirty = true;
|
term->grid.dirty = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue