Revert "termpty: better handle ';' in escape sequences. Closes T7475"

This reverts commit 3f432544df.
This commit is contained in:
Boris Faure 2018-11-20 10:34:37 +01:00
parent 3f432544df
commit 8fb44906cc
1 changed files with 290 additions and 297 deletions

View File

@ -104,11 +104,9 @@ _csi_arg_get(Eina_Unicode **ptr)
*ptr = b; *ptr = b;
return -1; return -1;
} }
if (*b == '\0')
{ if (!*b)
*ptr = NULL; goto error;
return -1;
}
while ((*b >= '0') && (*b <= '9')) while ((*b >= '0') && (*b <= '9'))
{ {
@ -121,21 +119,15 @@ _csi_arg_get(Eina_Unicode **ptr)
if (*b == ';') if (*b == ';')
{ {
if (b[1]) b++;
b++;
*ptr = b;
} }
else if (*b == '\0')
{ *ptr = b;
*ptr = NULL;
}
else
*ptr = b;
return sum; return sum;
error: error:
*ptr = NULL; *ptr = NULL;
return -2; return -1;
} }
static void static void
@ -653,10 +645,10 @@ _handle_esc_csi_truecolor_cmyk(Termpty *ty, Eina_Unicode **ptr)
} }
static void static void
_handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr, _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr)
const Eina_Unicode * const end)
{ {
Eina_Unicode *b = *ptr; Eina_Unicode *b = *ptr;
int first = 1;
if (b && (*b == '>')) if (b && (*b == '>'))
{ // key resources used by xterm { // key resources used by xterm
@ -664,293 +656,296 @@ _handle_esc_csi_color_set(Termpty *ty, Eina_Unicode **ptr,
return; return;
} }
DBG("color set"); DBG("color set");
while (b && b <= end) while (b)
{ {
int arg = _csi_arg_get(&b); int arg = _csi_arg_get(&b);
DBG("arg=%d b:%p", arg, b); if ((first) && (!b))
switch (arg) termpty_reset_att(&(ty->termstate.att));
else if (b)
{ {
case -1: first = 0;
EINA_FALLTHROUGH; switch (arg)
case 0: // reset to normal {
termpty_reset_att(&(ty->termstate.att)); case 0: // reset to normal
break; termpty_reset_att(&(ty->termstate.att));
case 1: // bold/bright break;
ty->termstate.att.bold = 1; case 1: // bold/bright
break; ty->termstate.att.bold = 1;
case 2: // faint break;
ty->termstate.att.faint = 1; case 2: // faint
break; ty->termstate.att.faint = 1;
case 3: // italic break;
ty->termstate.att.italic = 1; case 3: // italic
break; ty->termstate.att.italic = 1;
case 4: // underline break;
ty->termstate.att.underline = 1; case 4: // underline
break; ty->termstate.att.underline = 1;
case 5: // blink break;
ty->termstate.att.blink = 1; case 5: // blink
break; ty->termstate.att.blink = 1;
case 6: // blink rapid break;
ty->termstate.att.blink2 = 1; case 6: // blink rapid
break; ty->termstate.att.blink2 = 1;
case 7: // reverse break;
ty->termstate.att.inverse = 1; case 7: // reverse
break; ty->termstate.att.inverse = 1;
case 8: // invisible break;
ty->termstate.att.invisible = 1; case 8: // invisible
break; ty->termstate.att.invisible = 1;
case 9: // strikethrough break;
ty->termstate.att.strike = 1; case 9: // strikethrough
break; ty->termstate.att.strike = 1;
case 20: // fraktur! break;
ty->termstate.att.fraktur = 1; case 20: // fraktur!
break; ty->termstate.att.fraktur = 1;
case 21: // no bold/bright break;
ty->termstate.att.bold = 0; case 21: // no bold/bright
break; ty->termstate.att.bold = 0;
case 22: // no bold/bright, no faint break;
ty->termstate.att.bold = 0; case 22: // no bold/bright, no faint
ty->termstate.att.faint = 0; ty->termstate.att.bold = 0;
break; ty->termstate.att.faint = 0;
case 23: // no italic, not fraktur break;
ty->termstate.att.italic = 0; case 23: // no italic, not fraktur
ty->termstate.att.fraktur = 0; ty->termstate.att.italic = 0;
break; ty->termstate.att.fraktur = 0;
case 24: // no underline break;
ty->termstate.att.underline = 0; case 24: // no underline
break; ty->termstate.att.underline = 0;
case 25: // no blink break;
ty->termstate.att.blink = 0; case 25: // no blink
ty->termstate.att.blink2 = 0; ty->termstate.att.blink = 0;
break; ty->termstate.att.blink2 = 0;
case 27: // no reverse break;
ty->termstate.att.inverse = 0; case 27: // no reverse
break; ty->termstate.att.inverse = 0;
case 28: // no invisible break;
ty->termstate.att.invisible = 0; case 28: // no invisible
break; ty->termstate.att.invisible = 0;
case 29: // no strikethrough break;
ty->termstate.att.strike = 0; case 29: // no strikethrough
break; ty->termstate.att.strike = 0;
case 30: // fg break;
case 31: case 30: // fg
case 32: case 31:
case 33: case 32:
case 34: case 33:
case 35: case 34:
case 36: case 35:
case 37: case 36:
ty->termstate.att.fg256 = 0; case 37:
ty->termstate.att.fg = (arg - 30) + COL_BLACK; ty->termstate.att.fg256 = 0;
ty->termstate.att.fgintense = 0; ty->termstate.att.fg = (arg - 30) + COL_BLACK;
break; ty->termstate.att.fgintense = 0;
case 38: // xterm 256 fg color ??? break;
arg = _csi_arg_get(&b); case 38: // xterm 256 fg color ???
switch (arg) arg = _csi_arg_get(&b);
{ switch (arg)
case 1: {
ty->termstate.att.fg256 = 0; case 1:
ty->termstate.att.fg = COL_INVIS; ty->termstate.att.fg256 = 0;
break; ty->termstate.att.fg = COL_INVIS;
case 2: break;
ty->termstate.att.fg256 = 1; case 2:
ty->termstate.att.fg =
_handle_esc_csi_truecolor_rgb(ty, &b);
DBG("truecolor RGB fg: approximation got color %d",
ty->termstate.att.fg);
break;
case 3:
ty->termstate.att.fg256 = 1;
ty->termstate.att.fg =
_handle_esc_csi_truecolor_cmy(ty, &b);
DBG("truecolor CMY fg: approximation got color %d",
ty->termstate.att.fg);
break;
case 4:
ty->termstate.att.fg256 = 1;
ty->termstate.att.fg =
_handle_esc_csi_truecolor_cmyk(ty, &b);
DBG("truecolor CMYK fg: approximation got color %d",
ty->termstate.att.fg);
break;
case 5:
// then get next arg - should be color index 0-255
arg = _csi_arg_get(&b);
if (!b) ERR("Failed xterm 256 color fg esc val");
else if (arg < 0 || arg > 255)
ERR("Invalid fg color %d", arg);
else
{
ty->termstate.att.fg256 = 1; ty->termstate.att.fg256 = 1;
ty->termstate.att.fg = arg; ty->termstate.att.fg =
} _handle_esc_csi_truecolor_rgb(ty, &b);
break; DBG("truecolor RGB fg: approximation got color %d",
default: ty->termstate.att.fg);
ERR("Failed xterm 256 color fg (got %d)", arg); break;
} case 3:
ty->termstate.att.fgintense = 0; ty->termstate.att.fg256 = 1;
break; ty->termstate.att.fg =
case 39: // default fg color _handle_esc_csi_truecolor_cmy(ty, &b);
ty->termstate.att.fg256 = 0; DBG("truecolor CMY fg: approximation got color %d",
ty->termstate.att.fg = COL_DEF; ty->termstate.att.fg);
ty->termstate.att.fgintense = 0; break;
break; case 4:
case 40: // bg ty->termstate.att.fg256 = 1;
case 41: ty->termstate.att.fg =
case 42: _handle_esc_csi_truecolor_cmyk(ty, &b);
case 43: DBG("truecolor CMYK fg: approximation got color %d",
case 44: ty->termstate.att.fg);
case 45: break;
case 46: case 5:
case 47: // then get next arg - should be color index 0-255
ty->termstate.att.bg256 = 0; arg = _csi_arg_get(&b);
ty->termstate.att.bg = (arg - 40) + COL_BLACK; if (!b) ERR("Failed xterm 256 color fg esc val");
ty->termstate.att.bgintense = 0; else if (arg < 0 || arg > 255)
break; ERR("Invalid fg color %d", arg);
case 48: // xterm 256 bg color ??? else
arg = _csi_arg_get(&b); {
switch (arg) ty->termstate.att.fg256 = 1;
{ ty->termstate.att.fg = arg;
case 1: }
ty->termstate.att.bg256 = 0; break;
ty->termstate.att.bg = COL_INVIS; default:
break; ERR("Failed xterm 256 color fg (got %d)", arg);
case 2: }
ty->termstate.att.bg256 = 1; ty->termstate.att.fgintense = 0;
ty->termstate.att.bg = break;
_handle_esc_csi_truecolor_rgb(ty, &b); case 39: // default fg color
DBG("truecolor RGB bg: approximation got color %d", ty->termstate.att.fg256 = 0;
ty->termstate.att.bg); ty->termstate.att.fg = COL_DEF;
break; ty->termstate.att.fgintense = 0;
case 3: break;
ty->termstate.att.bg256 = 1; case 40: // bg
ty->termstate.att.bg = case 41:
_handle_esc_csi_truecolor_cmy(ty, &b); case 42:
DBG("truecolor CMY bg: approximation got color %d", case 43:
ty->termstate.att.bg); case 44:
break; case 45:
case 4: case 46:
ty->termstate.att.bg256 = 1; case 47:
ty->termstate.att.bg = ty->termstate.att.bg256 = 0;
_handle_esc_csi_truecolor_cmyk(ty, &b); ty->termstate.att.bg = (arg - 40) + COL_BLACK;
DBG("truecolor CMYK bg: approximation got color %d", ty->termstate.att.bgintense = 0;
ty->termstate.att.bg); break;
break; case 48: // xterm 256 bg color ???
case 5: arg = _csi_arg_get(&b);
// then get next arg - should be color index 0-255 switch (arg)
arg = _csi_arg_get(&b); {
if (!b) ERR("Failed xterm 256 color bg esc val"); case 1:
else if (arg < 0 || arg > 255) ty->termstate.att.bg256 = 0;
ERR("Invalid bg color %d", arg); ty->termstate.att.bg = COL_INVIS;
else break;
{ case 2:
ty->termstate.att.bg256 = 1; ty->termstate.att.bg256 = 1;
ty->termstate.att.bg = arg; ty->termstate.att.bg =
} _handle_esc_csi_truecolor_rgb(ty, &b);
break; DBG("truecolor RGB bg: approximation got color %d",
default: ty->termstate.att.bg);
ERR("Failed xterm 256 color bg (got %d)", arg); break;
} case 3:
ty->termstate.att.bgintense = 0; ty->termstate.att.bg256 = 1;
break; ty->termstate.att.bg =
case 49: // default bg color _handle_esc_csi_truecolor_cmy(ty, &b);
ty->termstate.att.bg256 = 0; DBG("truecolor CMY bg: approximation got color %d",
ty->termstate.att.bg = COL_DEF; ty->termstate.att.bg);
ty->termstate.att.bgintense = 0; break;
break; case 4:
case 51: ty->termstate.att.bg256 = 1;
WRN("TODO: support SGR 51 - framed attribute"); ty->termstate.att.bg =
ty->termstate.att.framed = 1; _handle_esc_csi_truecolor_cmyk(ty, &b);
break; DBG("truecolor CMYK bg: approximation got color %d",
case 52: ty->termstate.att.bg);
ty->termstate.att.encircled = 1; break;
break; case 5:
case 53: // then get next arg - should be color index 0-255
WRN("TODO: support SGR 51 - overlined attribute"); arg = _csi_arg_get(&b);
ty->termstate.att.overlined = 1; if (!b) ERR("Failed xterm 256 color bg esc val");
break; else if (arg < 0 || arg > 255)
case 54: ERR("Invalid bg color %d", arg);
ty->termstate.att.framed = 0; else
ty->termstate.att.encircled = 0; {
break; ty->termstate.att.bg256 = 1;
case 55: ty->termstate.att.bg = arg;
ty->termstate.att.overlined = 0; }
break; break;
case 90: // fg default:
case 91: ERR("Failed xterm 256 color bg (got %d)", arg);
case 92: }
case 93: ty->termstate.att.bgintense = 0;
case 94: break;
case 95: case 49: // default bg color
case 96: ty->termstate.att.bg256 = 0;
case 97: ty->termstate.att.bg = COL_DEF;
ty->termstate.att.fg256 = 0; ty->termstate.att.bgintense = 0;
ty->termstate.att.fg = (arg - 90) + COL_BLACK; break;
ty->termstate.att.fgintense = 1; case 51:
break; WRN("TODO: support SGR 51 - framed attribute");
case 98: // xterm 256 fg color ??? ty->termstate.att.framed = 1;
// now check if next arg is 5 break;
arg = _csi_arg_get(&b); case 52:
if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg); ty->termstate.att.encircled = 1;
else break;
{ case 53:
// then get next arg - should be color index 0-255 WRN("TODO: support SGR 51 - overlined attribute");
ty->termstate.att.overlined = 1;
break;
case 54:
ty->termstate.att.framed = 0;
ty->termstate.att.encircled = 0;
break;
case 55:
ty->termstate.att.overlined = 0;
break;
case 90: // fg
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
ty->termstate.att.fg256 = 0;
ty->termstate.att.fg = (arg - 90) + COL_BLACK;
ty->termstate.att.fgintense = 1;
break;
case 98: // xterm 256 fg color ???
// now check if next arg is 5
arg = _csi_arg_get(&b); arg = _csi_arg_get(&b);
if (!b) ERR("Failed xterm 256 color fg esc val"); if (arg != 5) ERR("Failed xterm 256 color fg esc 5 (got %d)", arg);
else if (arg < 0 || arg > 255)
ERR("Invalid fg color %d", arg);
else else
{ {
ty->termstate.att.fg256 = 1; // then get next arg - should be color index 0-255
ty->termstate.att.fg = arg; arg = _csi_arg_get(&b);
if (!b) ERR("Failed xterm 256 color fg esc val");
else if (arg < 0 || arg > 255)
ERR("Invalid fg color %d", arg);
else
{
ty->termstate.att.fg256 = 1;
ty->termstate.att.fg = arg;
}
} }
} ty->termstate.att.fgintense = 1;
ty->termstate.att.fgintense = 1; break;
break; case 99: // default fg color
case 99: // default fg color ty->termstate.att.fg256 = 0;
ty->termstate.att.fg256 = 0; ty->termstate.att.fg = COL_DEF;
ty->termstate.att.fg = COL_DEF; ty->termstate.att.fgintense = 1;
ty->termstate.att.fgintense = 1; break;
break; case 100: // bg
case 100: // bg case 101:
case 101: case 102:
case 102: case 103:
case 103: case 104:
case 104: case 105:
case 105: case 106:
case 106: case 107:
case 107: ty->termstate.att.bg256 = 0;
ty->termstate.att.bg256 = 0; ty->termstate.att.bg = (arg - 100) + COL_BLACK;
ty->termstate.att.bg = (arg - 100) + COL_BLACK; ty->termstate.att.bgintense = 1;
ty->termstate.att.bgintense = 1; break;
break; case 108: // xterm 256 bg color ???
case 108: // xterm 256 bg color ??? // now check if next arg is 5
// now check if next arg is 5
arg = _csi_arg_get(&b);
if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
else
{
// then get next arg - should be color index 0-255
arg = _csi_arg_get(&b); arg = _csi_arg_get(&b);
if (!b) ERR("Failed xterm 256 color bg esc val"); if (arg != 5) ERR("Failed xterm 256 color bg esc 5 (got %d)", arg);
else if (arg < 0 || arg > 255)
ERR("Invalid bg color %d", arg);
else else
{ {
ty->termstate.att.bg256 = 1; // then get next arg - should be color index 0-255
ty->termstate.att.bg = arg; arg = _csi_arg_get(&b);
if (!b) ERR("Failed xterm 256 color bg esc val");
else if (arg < 0 || arg > 255)
ERR("Invalid bg color %d", arg);
else
{
ty->termstate.att.bg256 = 1;
ty->termstate.att.bg = arg;
}
} }
} ty->termstate.att.bgintense = 1;
ty->termstate.att.bgintense = 1; break;
break; case 109: // default bg color
case 109: // default bg color ty->termstate.att.bg256 = 0;
ty->termstate.att.bg256 = 0; ty->termstate.att.bg = COL_DEF;
ty->termstate.att.bg = COL_DEF; ty->termstate.att.bgintense = 1;
ty->termstate.att.bgintense = 1; break;
break; default: // not handled???
default: // not handled??? WRN("Unhandled color cmd [%i]", arg);
WRN("Unhandled color cmd [%i]", arg); break;
break; }
} }
} }
} }
@ -1260,9 +1255,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
ERR("csi parsing overflowed, skipping the whole buffer (binary data?)"); ERR("csi parsing overflowed, skipping the whole buffer (binary data?)");
return cc - c; return cc - c;
} }
if (cc == ce) if (cc == ce) return 0;
return 0; *b = 0;
*b = '\0';
be = b; be = b;
b = buf; b = buf;
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf); DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf);
@ -1290,8 +1284,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
case 'A': // cursor up N (CUU) case 'A': // cursor up N (CUU)
CUU: CUU:
arg = _csi_arg_get(&b); arg = _csi_arg_get(&b);
if (arg < 1) if (arg < 1) arg = 1;
arg = 1;
DBG("cursor up %d", arg); DBG("cursor up %d", arg);
ty->termstate.wrapnext = 0; ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg); ty->cursor_state.cy = MAX(0, ty->cursor_state.cy - arg);
@ -1632,7 +1625,7 @@ HVP:
_handle_esc_csi_reset_mode(ty, *cc, b); _handle_esc_csi_reset_mode(ty, *cc, b);
break; break;
case 'm': // color set case 'm': // color set
_handle_esc_csi_color_set(ty, &b, be); _handle_esc_csi_color_set(ty, &b);
break; break;
case 'n': case 'n':
_handle_esc_csi_dsr(ty, b); _handle_esc_csi_dsr(ty, b);