termptyesc: correctly handle DECOM

also fix regions with only one argument
This commit is contained in:
Boris Faure 2017-05-31 00:39:02 +02:00
parent 6ce96da8c4
commit 816f60369f
2 changed files with 26 additions and 10 deletions

View File

@ -136,7 +136,7 @@ struct _Termpty
unsigned char chset[4]; unsigned char chset[4];
int top_margin, bottom_margin; int top_margin, bottom_margin;
int had_cr_x, had_cr_y; int had_cr_x, had_cr_y;
int margin_top; // soon, more to come... unsigned int restrict_cursor : 1;
unsigned int multibyte : 1; unsigned int multibyte : 1;
unsigned int alt_kp : 1; unsigned int alt_kp : 1;
unsigned int insert : 1; unsigned int insert : 1;

View File

@ -254,15 +254,19 @@ _handle_esc_csi_reset_mode(Termpty *ty, Eina_Unicode cc, Eina_Unicode *b)
ty->termstate.reverse = mode; ty->termstate.reverse = mode;
break; break;
case 6: case 6:
/* DECOM */
if (mode) if (mode)
{ {
ty->termstate.margin_top = ty->cursor_state.cy; /* set, within margins */
ty->termstate.restrict_cursor = 1;
ty->cursor_state.cx = 0; ty->cursor_state.cx = 0;
ty->cursor_state.cy = ty->termstate.top_margin;
} }
else else
{ {
ty->termstate.restrict_cursor = 0;
ty->cursor_state.cx = 0; ty->cursor_state.cx = 0;
ty->termstate.margin_top = 0; ty->cursor_state.cy = 0;
} }
DBG("origin mode (%d): cursor is at 0,0" DBG("origin mode (%d): cursor is at 0,0"
" cursor limited to screen/start point" " cursor limited to screen/start point"
@ -782,14 +786,19 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, 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 case 'A': // cursor up N CUU
case 'e': // cursor up N case 'e': // cursor up N, VPR
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);
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);
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
if (ty->termstate.restrict_cursor && (ty->termstate.top_margin != 0)
&& (ty->cursor_state.cy < ty->termstate.top_margin))
{
ty->cursor_state.cy = ty->termstate.top_margin;
}
break; break;
case 'B': // cursor down N case 'B': // cursor down N
arg = _csi_arg_get(&b); arg = _csi_arg_get(&b);
@ -798,6 +807,11 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
ty->termstate.wrapnext = 0; ty->termstate.wrapnext = 0;
ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg); ty->cursor_state.cy = MIN(ty->h - 1, ty->cursor_state.cy + arg);
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
if (ty->termstate.restrict_cursor && (ty->termstate.bottom_margin != 0)
&& (ty->cursor_state.cy > ty->termstate.bottom_margin))
{
ty->cursor_state.cy = ty->termstate.bottom_margin;
}
break; break;
case 'D': // cursor left N case 'D': // cursor left N
arg = _csi_arg_get(&b); arg = _csi_arg_get(&b);
@ -834,7 +848,6 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (b) if (b)
{ {
ty->cursor_state.cy = arg; ty->cursor_state.cy = arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
arg = _csi_arg_get(&b); arg = _csi_arg_get(&b);
if (arg < 1) arg = 1; if (arg < 1) arg = 1;
arg--; arg--;
@ -845,10 +858,10 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
if (b) if (b)
{ {
ty->cursor_state.cx = arg; ty->cursor_state.cx = arg;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
} }
} }
ty->cursor_state.cy += ty->termstate.margin_top; TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
ty->cursor_state.cy += ty->termstate.top_margin;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h); TERMPTY_RESTRICT_FIELD(ty->cursor_state.cy, 0, ty->h);
break; break;
case 'G': // to column N case 'G': // to column N
@ -1061,8 +1074,8 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
arg2 = _csi_arg_get(&b); arg2 = _csi_arg_get(&b);
if (!b) if (!b)
{ {
WRN("failed to give 2 regions args reset region"); TERMPTY_RESTRICT_FIELD(arg, 1, ty->h);
ty->termstate.top_margin = 0; ty->termstate.top_margin = arg - 1;
ty->termstate.bottom_margin = 0; ty->termstate.bottom_margin = 0;
} }
else else
@ -1084,6 +1097,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, Eina_Unicode *ce)
ty->termstate.bottom_margin = 0; ty->termstate.bottom_margin = 0;
} }
} }
ty->cursor_state.cx = 0;
ty->cursor_state.cy = (ty->termstate.restrict_cursor) ?
ty->termstate.top_margin : 0;
} }
break; break;
case 's': // store cursor pos case 's': // store cursor pos