mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-14 05:33:59 -04:00
csi: implement CSI Pn P (DCH - delete character)
This commit is contained in:
parent
4c7dbee221
commit
e600e75810
1 changed files with 51 additions and 24 deletions
75
csi.c
75
csi.c
|
|
@ -14,6 +14,8 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "grid.h"
|
#include "grid.h"
|
||||||
|
|
||||||
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
csi_sgr(struct terminal *term)
|
csi_sgr(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
|
@ -136,11 +138,39 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
case 'm':
|
case 'm':
|
||||||
return csi_sgr(term);
|
return csi_sgr(term);
|
||||||
|
|
||||||
|
case 'A': {
|
||||||
|
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
||||||
|
grid_cursor_up(&term->grid, count);
|
||||||
|
//LOG_DBG("CSI: A: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'B': {
|
||||||
|
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
||||||
|
grid_cursor_down(&term->grid, count);
|
||||||
|
//LOG_DBG("CSI: B: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'C': {
|
||||||
|
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
||||||
|
grid_cursor_right(&term->grid, count);
|
||||||
|
//LOG_DBG("CSI: C: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'D': {
|
||||||
|
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
||||||
|
grid_cursor_left(&term->grid, count);
|
||||||
|
//LOG_DBG("CSI: D: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'J': {
|
case 'J': {
|
||||||
/* Erase screen */
|
/* Erase screen */
|
||||||
|
|
||||||
int param = 0;
|
int param = 0;
|
||||||
if (term->vt.params.idx >= 1)
|
if (term->vt.params.idx > 0)
|
||||||
param = term->vt.params.v[0].value;
|
param = term->vt.params.v[0].value;
|
||||||
|
|
||||||
int start = -1;
|
int start = -1;
|
||||||
|
|
@ -177,7 +207,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
/* Erase line */
|
/* Erase line */
|
||||||
|
|
||||||
int param = 0;
|
int param = 0;
|
||||||
if (term->vt.params.idx >= 0)
|
if (term->vt.params.idx > 0)
|
||||||
param = term->vt.params.v[0].value;
|
param = term->vt.params.v[0].value;
|
||||||
|
|
||||||
int start = -1;
|
int start = -1;
|
||||||
|
|
@ -216,31 +246,28 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'A': {
|
case 'P': {
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
/* DCH: Delete character */
|
||||||
grid_cursor_up(&term->grid, count);
|
int param = 1;
|
||||||
//LOG_DBG("CSI: A: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
if (term->vt.params.idx > 0)
|
||||||
break;
|
param = term->vt.params.v[0].value;
|
||||||
}
|
|
||||||
|
|
||||||
case 'B': {
|
/* Only delete up to the right margin */
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
const int max_end = grid_cursor_linear(
|
||||||
grid_cursor_down(&term->grid, count);
|
&term->grid, term->grid.cursor.row, term->grid.cols);
|
||||||
//LOG_DBG("CSI: B: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'C': {
|
int start = term->grid.linear_cursor;
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int end = min(start + param, max_end);
|
||||||
grid_cursor_right(&term->grid, count);
|
|
||||||
//LOG_DBG("CSI: C: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'D': {
|
/* Erase the requested number of characters */
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
grid_erase(&term->grid, start, end);
|
||||||
grid_cursor_left(&term->grid, count);
|
|
||||||
//LOG_DBG("CSI: D: row = %d, col = %d", term->grid.cursor.row, term->grid.cursor.col);
|
/* Move remaining (up til the right margin) characters */
|
||||||
|
int count = max_end - end;
|
||||||
|
memmove(&term->grid.cells[start],
|
||||||
|
&term->grid.cells[end],
|
||||||
|
count * sizeof(term->grid.cells[0]));
|
||||||
|
grid_damage_update(&term->grid, term->grid.linear_cursor, count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue