termptyesc: support DECIC/DECDC + tests

This commit is contained in:
Boris Faure 2018-12-30 18:36:02 +01:00
parent fee45b5492
commit 12cc6aaf42
4 changed files with 247 additions and 1 deletions

View File

@ -2077,6 +2077,122 @@ _handle_esc_csi_decsace(Termpty *ty, Eina_Unicode **b)
}
}
static void
_handle_esc_csi_decic(Termpty *ty, Eina_Unicode **b)
{
int arg = _csi_arg_get(ty, b);
int old_insert = ty->termstate.insert;
Eina_Unicode blank[1] = { ' ' };
int top = 0;
int bottom = ty->h;
int old_cx = ty->cursor_state.cx;
int old_cy = ty->cursor_state.cy;
DBG("DECIC Insert %d Column", arg);
if (arg == -CSI_ARG_ERROR)
return;
if (arg < 1)
arg = 1;
if (ty->termstate.top_margin > 0)
{
if (ty->cursor_state.cy < ty->termstate.top_margin)
return;
top = ty->termstate.top_margin;
}
if (ty->termstate.bottom_margin != 0)
{
if (ty->cursor_state.cy >= ty->termstate.bottom_margin)
return;
bottom = ty->termstate.bottom_margin;
}
if (((ty->termstate.left_margin > 0)
&& (ty->cursor_state.cx < ty->termstate.left_margin))
|| ((ty->termstate.right_margin > 0)
&& (ty->cursor_state.cx >= ty->termstate.right_margin)))
return;
ty->termstate.insert = 1;
for (; top < bottom; top++)
{
int i;
/* Insert a left column */
ty->cursor_state.cy = top;
ty->cursor_state.cx = old_cx;
ty->termstate.wrapnext = 0;
for (i = 0; i < arg; i++)
termpty_text_append(ty, blank, 1);
}
ty->termstate.insert = old_insert;
ty->cursor_state.cx = old_cx;
ty->cursor_state.cy = old_cy;
}
static void
_handle_esc_csi_decdc(Termpty *ty, Eina_Unicode **b)
{
int arg = _csi_arg_get(ty, b);
int y = 0;
int max_y = ty->h;
int max_x = ty->w;
int lim;
DBG("DECDC Delete %d Column", arg);
if (arg == -CSI_ARG_ERROR)
return;
if (arg < 1)
arg = 1;
if (ty->termstate.top_margin > 0)
{
if (ty->cursor_state.cy < ty->termstate.top_margin)
return;
y = ty->termstate.top_margin;
}
if (ty->termstate.bottom_margin != 0)
{
if (ty->cursor_state.cy >= ty->termstate.bottom_margin)
return;
max_y = ty->termstate.bottom_margin;
}
if (ty->termstate.right_margin > 0)
{
if (ty->cursor_state.cx >= ty->termstate.right_margin)
return;
max_x = ty->termstate.right_margin;
}
if (((ty->termstate.left_margin > 0)
&& (ty->cursor_state.cx < ty->termstate.left_margin)))
return;
TERMPTY_RESTRICT_FIELD(arg, 1, max_x + 1);
lim = max_x - arg;
for (; y < max_y; y++)
{
int x;
Termcell *cells = &(TERMPTY_SCREEN(ty, 0, y));
for (x = ty->cursor_state.cx; x < max_x; x++)
{
if (x < lim)
TERMPTY_CELL_COPY(ty, &(cells[x + arg]), &(cells[x]), 1);
else
{
cells[x].codepoint = ' ';
if (EINA_UNLIKELY(cells[x].att.link_id))
term_link_refcount_dec(ty, cells[x].att.link_id, 1);
cells[x].att = ty->termstate.att;
cells[x].att.link_id = 0;
cells[x].att.dblwidth = 0;
}
}
}
}
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@ -2563,10 +2679,26 @@ HVP:
_handle_esc_csi_decfra(ty, &b);
else if (*(cc-1) == '*')
_handle_esc_csi_decsace(ty, &b);
else
ty->decoding_error = EINA_TRUE;
break;
case 'z':
if (*(cc-1) == '$')
_handle_esc_csi_decera(ty, &b);
else
ty->decoding_error = EINA_TRUE;
break;
case '}':
if (*(cc-1) == '\'')
_handle_esc_csi_decic(ty, &b);
else
ty->decoding_error = EINA_TRUE;
break;
case '~':
if (*(cc-1) == '\'')
_handle_esc_csi_decdc(ty, &b);
else
ty->decoding_error = EINA_TRUE;
break;
default:
goto unhandled;

View File

@ -158,7 +158,8 @@ termpty_text_scroll_rev_test(Termpty *ty, Eina_Bool clear)
{
int b = 0;
if (ty->termstate.top_margin != 0) b = ty->termstate.top_margin;
if (ty->termstate.top_margin != 0)
b = ty->termstate.top_margin;
if (ty->cursor_state.cy < b)
{
termpty_text_scroll_rev(ty, clear);

112
tests/decic-decdc.sh Executable file
View File

@ -0,0 +1,112 @@
#!/bin/sh
# move to 0; 0
printf '\033[H'
# fill space
PL=0
for _ in $(seq 0 23); do
PL=$((PL+1))
if [ $PL -ge 9 ] ; then
PL=0
fi
for _ in $(seq 1 $PL); do
printf '#'
done
PR=$((10 - PL))
for _ in $(seq 0 6); do
printf '\033[0;1m\-'
printf '\033[0;46;1;4m/'
printf '\033[0;46;1;4m|'
printf '\033[0;1;4;7m\\'
printf '\033[0m~'
printf '\033[0;1m_'
printf '\033[0;31;7m>'
printf '\033[0;31;4;7m^'
printf '\033[0;1;7m<'
done
printf '\033[0m'
for _ in $(seq 1 $PR); do
printf '#'
done
done
# move to 0; 0
printf '\033[H'
#set color
printf '\033[43;32;3m'
# set top/bottom margins:
printf '\033[3;20r'
# allow left/right margins
printf '\033[?69h'
# set left/right margins:
printf '\033[5;75s'
#
# INSERT
#
# move to
printf '\033[2;2H'
# insert column, outside margin, do nothing
printf '\033[\047}'
# move to
printf '\033[2;8H'
# insert column, outside margin, do nothing
printf '\033[\047}'
# move to
printf '\033[5;2H'
# insert column, outside margin, do nothing
printf '\033[\047}'
# move to
printf '\033[10;12H'
# insert column
printf '\033[\047}'
# move to
printf '\033[10;17H'
# insert 0 column (but 1 actually)
printf '\033[0\047}'
# move to
printf '\033[10;21H'
# insert 3 columns
printf '\033[3\047}'
#
# DELETE
#
# move to
printf '\033[2;78H'
# insert column, outside margin, do nothing
printf '\033[\047~'
# move to
printf '\033[10;78H'
# insert column, outside margin, do nothing
printf '\033[\047~'
# move to
printf '\033[2;60H'
# insert column, outside margin, do nothing
printf '\033[\047~'
# move to
printf '\033[10;50H'
# delete column
printf '\033[\047~'
# move to
printf '\033[10;55H'
# delete 0 column (but 1 actually)
printf '\033[0\047~'
# move to
printf '\033[10;60H'
# delete 3 columns
printf '\033[3\047~'

View File

@ -49,3 +49,4 @@ decrara-rectangular-no-restrict-cursor.sh be9836ff18eafb90795faecc042f34d6
decrara-rectangular-restrict-cursor.sh e98723f8f749e4902f7f4aaa677b85d6
decrara-no-rectangular-no-restrict-cursor.sh c375dd5d6538aff4c920b022f32f4ab0
decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33
decic-decdc.sh 6d67999a7c5c771281ff2229cdbdda76