mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-23 01:40:12 -05:00
csi: add function param_get()
Returns the value of parameter #idx, if available, or the specified default value. If the specified parameter does exist, but is 0, the default value is returned.
This commit is contained in:
parent
da0a65d499
commit
5b53fda5e6
1 changed files with 36 additions and 58 deletions
94
csi.c
94
csi.c
|
|
@ -61,6 +61,17 @@ initialize_colors256(void)
|
||||||
colors256[232 + i] = (11 * i) << 24 | (11 * i) << 16 | (11 * i) << 8 | 0xff;
|
colors256[232 + i] = (11 * i) << 24 | (11 * i) << 16 | (11 * i) << 8 | 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
param_get(const struct terminal *term, size_t idx, int default_value)
|
||||||
|
{
|
||||||
|
if (term->vt.params.idx > idx) {
|
||||||
|
int value = term->vt.params.v[idx].value;
|
||||||
|
return value != 0 ? value : default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sgr_reset(struct terminal *term)
|
sgr_reset(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
|
@ -248,9 +259,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
|
|
||||||
case 'd': {
|
case 'd': {
|
||||||
/* VPA - vertical line position absolute */
|
/* VPA - vertical line position absolute */
|
||||||
int row = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int row = param_get(term, 0, 1);
|
||||||
if (row == 0)
|
|
||||||
row = 1;
|
|
||||||
|
|
||||||
if (row > term->grid.rows)
|
if (row > term->grid.rows)
|
||||||
row = term->grid.rows;
|
row = term->grid.rows;
|
||||||
|
|
@ -262,44 +271,26 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
case 'm':
|
case 'm':
|
||||||
return csi_sgr(term);
|
return csi_sgr(term);
|
||||||
|
|
||||||
case 'A': {
|
case 'A':
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
grid_cursor_up(&term->grid, param_get(term, 0, 1));
|
||||||
if (count == 0)
|
|
||||||
count = 1;
|
|
||||||
grid_cursor_up(&term->grid, count);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'B': {
|
case 'B':
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
grid_cursor_down(&term->grid, param_get(term, 0, 1));
|
||||||
if (count == 0)
|
|
||||||
count = 1;
|
|
||||||
grid_cursor_down(&term->grid, count);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 'C': {
|
case 'C':
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
grid_cursor_right(&term->grid, param_get(term, 0, 1));
|
||||||
if (count == 0)
|
|
||||||
count = 1;
|
|
||||||
grid_cursor_right(&term->grid, count);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 'D': {
|
case 'D':
|
||||||
int count = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
grid_cursor_left(&term->grid, param_get(term, 0, 1));
|
||||||
if (count == 0)
|
|
||||||
count = 1;
|
|
||||||
grid_cursor_left(&term->grid, count);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 'G': {
|
case 'G': {
|
||||||
/* Cursor horizontal absolute */
|
/* Cursor horizontal absolute */
|
||||||
int col = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int col = param_get(term, 0, 1);
|
||||||
if (col == 0)
|
|
||||||
col = 1;
|
|
||||||
|
|
||||||
if (col > term->grid.cols)
|
if (col > term->grid.cols)
|
||||||
col = term->grid.cols;
|
col = term->grid.cols;
|
||||||
|
|
@ -310,13 +301,8 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
|
|
||||||
case 'H': {
|
case 'H': {
|
||||||
/* Move cursor */
|
/* Move cursor */
|
||||||
int row = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int row = param_get(term, 0, 1);
|
||||||
int col = term->vt.params.idx > 1 ? term->vt.params.v[1].value : 1;
|
int col = param_get(term, 1, 1);
|
||||||
|
|
||||||
if (row == 0)
|
|
||||||
row = 1;
|
|
||||||
if (col == 0)
|
|
||||||
col = 1;
|
|
||||||
|
|
||||||
if (row > term->grid.rows)
|
if (row > term->grid.rows)
|
||||||
row = term->grid.rows;
|
row = term->grid.rows;
|
||||||
|
|
@ -330,7 +316,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
case 'J': {
|
case 'J': {
|
||||||
/* Erase screen */
|
/* Erase screen */
|
||||||
|
|
||||||
int param = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 0;
|
int param = param_get(term, 0, 0);
|
||||||
int start = -1;
|
int start = -1;
|
||||||
int end = -1;
|
int end = -1;
|
||||||
switch (param) {
|
switch (param) {
|
||||||
|
|
@ -364,7 +350,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
case 'K': {
|
case 'K': {
|
||||||
/* Erase line */
|
/* Erase line */
|
||||||
|
|
||||||
int param = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 0;
|
int param = param_get(term, 0, 0);
|
||||||
int start = -1;
|
int start = -1;
|
||||||
int end = -1;
|
int end = -1;
|
||||||
switch (param) {
|
switch (param) {
|
||||||
|
|
@ -405,7 +391,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int count = min(
|
int count = min(
|
||||||
term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1,
|
param_get(term, 0, 1),
|
||||||
term->grid.scrolling_region.end - term->grid.cursor.row);
|
term->grid.scrolling_region.end - term->grid.cursor.row);
|
||||||
|
|
||||||
LOG_DBG("reverse partial: %d, %d rows",
|
LOG_DBG("reverse partial: %d, %d rows",
|
||||||
|
|
@ -425,7 +411,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int count = min(
|
int count = min(
|
||||||
term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1,
|
param_get(term, 0, 1),
|
||||||
term->grid.scrolling_region.end - term->grid.cursor.row);
|
term->grid.scrolling_region.end - term->grid.cursor.row);
|
||||||
|
|
||||||
grid_scroll_partial(
|
grid_scroll_partial(
|
||||||
|
|
@ -437,38 +423,30 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
|
|
||||||
case 'P': {
|
case 'P': {
|
||||||
/* DCH: Delete character */
|
/* DCH: Delete character */
|
||||||
int param = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int count = param_get(term, 0, 1);
|
||||||
if (param == 0)
|
|
||||||
param = 1;
|
|
||||||
|
|
||||||
/* Only delete up to the right margin */
|
/* Only delete up to the right margin */
|
||||||
const int max_end = grid_cursor_linear(
|
const int max_end = grid_cursor_linear(
|
||||||
&term->grid, term->grid.cursor.row, term->grid.cols);
|
&term->grid, term->grid.cursor.row, term->grid.cols);
|
||||||
|
|
||||||
int start = term->grid.linear_cursor;
|
int start = term->grid.linear_cursor;
|
||||||
int end = min(start + param, max_end);
|
int end = min(start + count, max_end);
|
||||||
|
|
||||||
/* Erase the requested number of characters */
|
/* Erase the requested number of characters */
|
||||||
grid_erase(&term->grid, start, end);
|
grid_erase(&term->grid, start, end);
|
||||||
|
|
||||||
/* Move remaining (up til the right margin) characters */
|
/* Move remaining (up til the right margin) characters */
|
||||||
int count = max_end - end;
|
int remaining = max_end - end;
|
||||||
memmove(&term->grid.cells[start],
|
memmove(&term->grid.cells[start],
|
||||||
&term->grid.cells[end],
|
&term->grid.cells[end],
|
||||||
count * sizeof(term->grid.cells[0]));
|
remaining * sizeof(term->grid.cells[0]));
|
||||||
grid_damage_update(&term->grid, term->grid.linear_cursor, count);
|
grid_damage_update(&term->grid, term->grid.linear_cursor, remaining);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'r': {
|
case 'r': {
|
||||||
int start = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 1;
|
int start = param_get(term, 0, 1);
|
||||||
int end = term->vt.params.idx > 1
|
int end = param_get(term, 1, term->grid.rows);
|
||||||
? term->vt.params.v[1].value : term->grid.rows;
|
|
||||||
|
|
||||||
if (start == 0)
|
|
||||||
start = 1;
|
|
||||||
if (end == 0)
|
|
||||||
end = term->grid.rows;
|
|
||||||
|
|
||||||
/* 1-based */
|
/* 1-based */
|
||||||
term->grid.scrolling_region.start = start - 1;
|
term->grid.scrolling_region.start = start - 1;
|
||||||
|
|
@ -496,7 +474,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
|
|
||||||
case 'n': {
|
case 'n': {
|
||||||
if (term->vt.params.idx > 0) {
|
if (term->vt.params.idx > 0) {
|
||||||
int param = term->vt.params.v[0].value;
|
int param = param_get(term, 0, 0);
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 6: {
|
case 6: {
|
||||||
/* u7 - cursor position query */
|
/* u7 - cursor position query */
|
||||||
|
|
@ -679,7 +657,7 @@ csi_dispatch(struct terminal *term, uint8_t final)
|
||||||
term->vt.intermediates.data[0] == '>') {
|
term->vt.intermediates.data[0] == '>') {
|
||||||
switch (final) {
|
switch (final) {
|
||||||
case 'c': {
|
case 'c': {
|
||||||
int param = term->vt.params.idx > 0 ? term->vt.params.v[0].value : 0;
|
int param = param_get(term, 0, 0);
|
||||||
if (param != 0) {
|
if (param != 0) {
|
||||||
LOG_ERR(
|
LOG_ERR(
|
||||||
"unimplemented: send device attributes with param = %d",
|
"unimplemented: send device attributes with param = %d",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue