forked from enlightenment/terminology
termptyesc: sort CSI escape code by ascii value
This commit is contained in:
parent
c4c769651c
commit
71c1b37675
|
@ -1217,24 +1217,13 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
}
|
}
|
||||||
if (cc == ce) return 0;
|
if (cc == ce) return 0;
|
||||||
*b = 0;
|
*b = 0;
|
||||||
|
be = b;
|
||||||
b = buf;
|
b = buf;
|
||||||
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
|
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
|
||||||
switch (*cc)
|
switch (*cc)
|
||||||
{
|
{
|
||||||
case 'm': // color set
|
/* sorted by ascii value */
|
||||||
_handle_esc_csi_color_set(ty, &b);
|
case '@': // insert N blank chars (ICH)
|
||||||
break;
|
|
||||||
case 'b': // repeat last char
|
|
||||||
if (ty->last_char)
|
|
||||||
{
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
|
|
||||||
DBG("REP: repeat %d times last char %x", arg, ty->last_char);
|
|
||||||
for (i = 0; i < arg; i++)
|
|
||||||
termpty_text_append(ty, &ty->last_char, 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '@': // insert N blank chars
|
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
|
||||||
DBG("insert %d blank chars", arg);
|
DBG("insert %d blank chars", arg);
|
||||||
|
@ -1252,8 +1241,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'A': // cursor up N CUU
|
case 'A': // cursor up N (CUU)
|
||||||
case 'e': // cursor up N, VPR
|
CUU:
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
if (arg < 1) arg = 1;
|
if (arg < 1) arg = 1;
|
||||||
DBG("cursor up %d", arg);
|
DBG("cursor up %d", arg);
|
||||||
|
@ -1279,21 +1268,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
ty->cursor_state.cy = ty->termstate.bottom_margin - 1;
|
ty->cursor_state.cy = ty->termstate.bottom_margin - 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'D': // cursor left N
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
if (arg < 1) arg = 1;
|
|
||||||
DBG("cursor left %d", arg);
|
|
||||||
ty->termstate.wrapnext = 0;
|
|
||||||
ty->cursor_state.cx -= arg;
|
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
|
||||||
if (ty->termstate.restrict_cursor && (ty->termstate.left_margin != 0)
|
|
||||||
&& (ty->cursor_state.cx < ty->termstate.left_margin))
|
|
||||||
{
|
|
||||||
ty->cursor_state.cx = ty->termstate.left_margin;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'C': // cursor right N
|
case 'C': // cursor right N
|
||||||
case 'a': // cursor right N
|
CUF:
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
if (arg < 1) arg = 1;
|
if (arg < 1) arg = 1;
|
||||||
DBG("cursor right %d", arg);
|
DBG("cursor right %d", arg);
|
||||||
|
@ -1306,25 +1282,18 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
ty->cursor_state.cx = ty->termstate.right_margin - 1;
|
ty->cursor_state.cx = ty->termstate.right_margin - 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'H': // cursor pos set (CUP)
|
case 'D': // cursor left N
|
||||||
case 'f': // cursor pos set (HVP)
|
|
||||||
_handle_esc_csi_cursor_pos_set(ty, &b, cc);
|
|
||||||
break;
|
|
||||||
case 'G': // to column N
|
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
if (arg < 1) arg = 1;
|
if (arg < 1) arg = 1;
|
||||||
DBG("to column %d", arg);
|
DBG("cursor left %d", arg);
|
||||||
ty->termstate.wrapnext = 0;
|
ty->termstate.wrapnext = 0;
|
||||||
ty->cursor_state.cx = arg - 1;
|
ty->cursor_state.cx -= arg;
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
||||||
break;
|
if (ty->termstate.restrict_cursor && (ty->termstate.left_margin != 0)
|
||||||
case 'd': // to row N
|
&& (ty->cursor_state.cx < ty->termstate.left_margin))
|
||||||
arg = _csi_arg_get(&b);
|
{
|
||||||
if (arg < 1) arg = 1;
|
ty->cursor_state.cx = ty->termstate.left_margin;
|
||||||
DBG("to row %d", arg);
|
}
|
||||||
ty->termstate.wrapnext = 0;
|
|
||||||
ty->cursor_state.cy = arg - 1;
|
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
|
||||||
break;
|
break;
|
||||||
case 'E': // down relative N rows, and to col 0
|
case 'E': // down relative N rows, and to col 0
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
|
@ -1344,31 +1313,76 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
||||||
ty->cursor_state.cx = 0;
|
ty->cursor_state.cx = 0;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'G': // to column N
|
||||||
_handle_esc_csi_decfra(ty, &b);
|
arg = _csi_arg_get(&b);
|
||||||
|
if (arg < 1) arg = 1;
|
||||||
|
DBG("to column %d", arg);
|
||||||
|
ty->termstate.wrapnext = 0;
|
||||||
|
ty->cursor_state.cx = arg - 1;
|
||||||
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
||||||
break;
|
break;
|
||||||
case 'X': // erase N chars
|
case 'H': // cursor pos set (CUP)
|
||||||
|
goto HVP;
|
||||||
|
case 'I':
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
||||||
DBG("ECH: erase %d chars", arg);
|
DBG("Cursor Forward Tabulation (CHT): %d", arg);
|
||||||
termpty_clear_line(ty, TERMPTY_CLR_END, arg);
|
_tab_forward(ty, arg);
|
||||||
break;
|
break;
|
||||||
case 'S': // scroll up N lines
|
case 'J':
|
||||||
|
if (*b == '?')
|
||||||
|
{
|
||||||
|
b++;
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
WRN("Unsupported selected erase in display %d", arg);
|
||||||
DBG("scroll up %d lines", arg);
|
}
|
||||||
for (i = 0; i < arg; i++)
|
else
|
||||||
termpty_text_scroll(ty, EINA_TRUE);
|
|
||||||
break;
|
|
||||||
case 'T': // scroll down N lines
|
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
if (arg < 1) arg = 0;
|
||||||
DBG("scroll down %d lines", arg);
|
/* 3J erases the backlog,
|
||||||
for (i = 0; i < arg; i++)
|
* 2J erases the screen,
|
||||||
termpty_text_scroll_rev(ty, EINA_TRUE);
|
* 1J erase from screen start to cursor,
|
||||||
|
* 0J erase form cursor to end of screen
|
||||||
|
*/
|
||||||
|
DBG("ED/DECSED %d: erase in display", arg);
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
case TERMPTY_CLR_END /* 0 */:
|
||||||
|
case TERMPTY_CLR_BEGIN /* 1 */:
|
||||||
|
case TERMPTY_CLR_ALL /* 2 */:
|
||||||
|
termpty_clear_screen(ty, arg);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
termpty_clear_backlog(ty);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERR("invalid EL/DECSEL argument %d", arg);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
|
||||||
|
if (*b == '?')
|
||||||
|
{
|
||||||
|
b++;
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
WRN("Unsupported selected erase in line %d", arg);
|
||||||
|
}
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
if (arg < 1) arg = 0;
|
||||||
|
DBG("EL/DECSEL %d: erase in line", arg);
|
||||||
|
switch (arg)
|
||||||
|
{
|
||||||
|
case TERMPTY_CLR_END:
|
||||||
|
case TERMPTY_CLR_BEGIN:
|
||||||
|
case TERMPTY_CLR_ALL:
|
||||||
|
termpty_clear_line(ty, arg, ty->w);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERR("invalid EL/DECSEL argument %d", arg);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'M': // delete N lines - cy
|
|
||||||
case 'L': // insert N lines - cy
|
case 'L': // insert N lines - cy
|
||||||
|
EINA_FALLTHROUGH;
|
||||||
|
case 'M': // delete N lines - cy
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
||||||
DBG("%s %d lines", (*cc == 'M') ? "delete" : "insert", arg);
|
DBG("%s %d lines", (*cc == 'M') ? "delete" : "insert", arg);
|
||||||
|
@ -1429,6 +1443,58 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'S': // scroll up N lines
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
||||||
|
DBG("scroll up %d lines", arg);
|
||||||
|
for (i = 0; i < arg; i++)
|
||||||
|
termpty_text_scroll(ty, EINA_TRUE);
|
||||||
|
break;
|
||||||
|
case 'T': // scroll down N lines
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
|
||||||
|
DBG("scroll down %d lines", arg);
|
||||||
|
for (i = 0; i < arg; i++)
|
||||||
|
termpty_text_scroll_rev(ty, EINA_TRUE);
|
||||||
|
break;
|
||||||
|
case 'X': // erase N chars
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
||||||
|
DBG("ECH: erase %d chars", arg);
|
||||||
|
termpty_clear_line(ty, TERMPTY_CLR_END, arg);
|
||||||
|
break;
|
||||||
|
case 'Z':
|
||||||
|
{
|
||||||
|
int cx = ty->cursor_state.cx;
|
||||||
|
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
DBG("Cursor Backward Tabulation (CBT): %d", arg);
|
||||||
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
||||||
|
for (; arg > 0; arg--)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
cx--;
|
||||||
|
}
|
||||||
|
while ((cx >= 0) && (!TAB_TEST(ty, cx)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ty->cursor_state.cx = cx;
|
||||||
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'a': // cursor right N
|
||||||
|
goto CUF;
|
||||||
|
case 'b': // repeat last char
|
||||||
|
if (ty->last_char)
|
||||||
|
{
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
|
||||||
|
DBG("REP: repeat %d times last char %x", arg, ty->last_char);
|
||||||
|
for (i = 0; i < arg; i++)
|
||||||
|
termpty_text_append(ty, &ty->last_char, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'c': // query device attributes
|
case 'c': // query device attributes
|
||||||
DBG("query device attributes");
|
DBG("query device attributes");
|
||||||
{
|
{
|
||||||
|
@ -1456,61 +1522,59 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
termpty_write(ty, bf, strlen(bf));
|
termpty_write(ty, bf, strlen(bf));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'J':
|
case 'd': // to row N
|
||||||
if (*b == '?')
|
|
||||||
{
|
|
||||||
b++;
|
|
||||||
arg = _csi_arg_get(&b);
|
arg = _csi_arg_get(&b);
|
||||||
WRN("Unsupported selected erase in display %d", arg);
|
if (arg < 1) arg = 1;
|
||||||
|
DBG("to row %d", arg);
|
||||||
|
ty->termstate.wrapnext = 0;
|
||||||
|
ty->cursor_state.cy = arg - 1;
|
||||||
|
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
|
||||||
|
break;
|
||||||
|
case 'e': // cursor up N (VPR)
|
||||||
|
goto CUU;
|
||||||
|
case 'f': // cursor pos set (HVP)
|
||||||
|
HVP:
|
||||||
|
_handle_esc_csi_cursor_pos_set(ty, &b, cc);
|
||||||
|
break;
|
||||||
|
case 'g': // clear tabulation
|
||||||
|
arg = _csi_arg_get(&b);
|
||||||
|
if (arg < 0) arg = 0;
|
||||||
|
if (arg == 0)
|
||||||
|
{
|
||||||
|
int cx = ty->cursor_state.cx;
|
||||||
|
TAB_UNSET(ty, cx);
|
||||||
|
}
|
||||||
|
else if (arg == 3)
|
||||||
|
{
|
||||||
|
termpty_clear_tabs_on_screen(ty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
if (arg < 1) arg = 0;
|
|
||||||
/* 3J erases the backlog,
|
|
||||||
* 2J erases the screen,
|
|
||||||
* 1J erase from screen start to cursor,
|
|
||||||
* 0J erase form cursor to end of screen
|
|
||||||
*/
|
|
||||||
DBG("ED/DECSED %d: erase in display", arg);
|
|
||||||
switch (arg)
|
|
||||||
{
|
{
|
||||||
case TERMPTY_CLR_END /* 0 */:
|
ERR("Tabulation Clear (TBC) with invalid argument: %d", arg);
|
||||||
case TERMPTY_CLR_BEGIN /* 1 */:
|
|
||||||
case TERMPTY_CLR_ALL /* 2 */:
|
|
||||||
termpty_clear_screen(ty, arg);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
termpty_clear_backlog(ty);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ERR("invalid EL/DECSEL argument %d", arg);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
|
|
||||||
if (*b == '?')
|
|
||||||
{
|
|
||||||
b++;
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
WRN("Unsupported selected erase in line %d", arg);
|
|
||||||
}
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
if (arg < 1) arg = 0;
|
|
||||||
DBG("EL/DECSEL %d: erase in line", arg);
|
|
||||||
switch (arg)
|
|
||||||
{
|
|
||||||
case TERMPTY_CLR_END:
|
|
||||||
case TERMPTY_CLR_BEGIN:
|
|
||||||
case TERMPTY_CLR_ALL:
|
|
||||||
termpty_clear_line(ty, arg, ty->w);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ERR("invalid EL/DECSEL argument %d", arg);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
|
EINA_FALLTHROUGH;
|
||||||
case 'l':
|
case 'l':
|
||||||
_handle_esc_csi_reset_mode(ty, *cc, b);
|
_handle_esc_csi_reset_mode(ty, *cc, b);
|
||||||
break;
|
break;
|
||||||
|
case 'm': // color set
|
||||||
|
_handle_esc_csi_color_set(ty, &b);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
_handle_esc_csi_dsr(ty, b);
|
||||||
|
break;
|
||||||
|
case 'p': // define key assignments based on keycode
|
||||||
|
if (b && *b == '!')
|
||||||
|
{
|
||||||
|
DBG("soft reset (DECSTR)");
|
||||||
|
termpty_reset_state(ty);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto unhandled;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
_handle_esc_csi_decstbm(ty, &b);
|
_handle_esc_csi_decstbm(ty, &b);
|
||||||
break;
|
break;
|
||||||
|
@ -1532,76 +1596,12 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
case 'u': // restore cursor pos
|
case 'u': // restore cursor pos
|
||||||
termpty_cursor_copy(ty, EINA_FALSE);
|
termpty_cursor_copy(ty, EINA_FALSE);
|
||||||
break;
|
break;
|
||||||
case 'p': // define key assignments based on keycode
|
case 'x':
|
||||||
if (b && *b == '!')
|
_handle_esc_csi_decfra(ty, &b);
|
||||||
{
|
|
||||||
DBG("soft reset (DECSTR)");
|
|
||||||
termpty_reset_state(ty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
goto unhandled;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
_handle_esc_csi_dsr(ty, b);
|
|
||||||
break;
|
|
||||||
/*
|
|
||||||
case 'R': // report cursor
|
|
||||||
break;
|
|
||||||
case 'q': // set/clear led's
|
|
||||||
break;
|
|
||||||
case 'x': // request terminal parameters
|
|
||||||
break;
|
|
||||||
case 'y': // invoke confidence test
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
case 'g': // clear tabulation
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
if (arg < 0) arg = 0;
|
|
||||||
if (arg == 0)
|
|
||||||
{
|
|
||||||
int cx = ty->cursor_state.cx;
|
|
||||||
TAB_UNSET(ty, cx);
|
|
||||||
}
|
|
||||||
else if (arg == 3)
|
|
||||||
{
|
|
||||||
termpty_clear_tabs_on_screen(ty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ERR("Tabulation Clear (TBC) with invalid argument: %d", arg);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'Z':
|
|
||||||
{
|
|
||||||
int cx = ty->cursor_state.cx;
|
|
||||||
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
DBG("Cursor Backward Tabulation (CBT): %d", arg);
|
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
|
||||||
for (; arg > 0; arg--)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
cx--;
|
|
||||||
}
|
|
||||||
while ((cx >= 0) && (!TAB_TEST(ty, cx)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ty->cursor_state.cx = cx;
|
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
_handle_esc_csi_decera(ty, &b);
|
_handle_esc_csi_decera(ty, &b);
|
||||||
break;
|
break;
|
||||||
case 'I':
|
|
||||||
arg = _csi_arg_get(&b);
|
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
|
|
||||||
DBG("Cursor Forward Tabulation (CHT): %d", arg);
|
|
||||||
_tab_forward(ty, arg);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
goto unhandled;
|
goto unhandled;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue