termptyesc: move ED handler to its own functions + add tests

terminology-1.4
Boris Faure 4 years ago
parent b76876e9c8
commit 06abd7e9bc
  1. 78
      src/bin/termptyesc.c
  2. 55
      tests/ed-0.sh
  3. 55
      tests/ed-1.sh
  4. 55
      tests/ed-2.sh
  5. 55
      tests/ed-3.sh
  6. 55
      tests/ed-4.sh
  7. 5
      tests/tests.results

@ -2493,6 +2493,46 @@ _handle_esc_csi_cht(Termpty *ty, Eina_Unicode **ptr)
_tab_forward(ty, arg);
}
static void
_handle_esc_csi_ed(Termpty *ty, Eina_Unicode **ptr)
{
Eina_Unicode *b = *ptr;
int arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
return;
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 */:
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);
ty->decoding_error = EINA_TRUE;
}
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
}
static void
_handle_esc_csi_decsed(Termpty *ty, Eina_Unicode **ptr)
{
WRN("DECSED - Selective Erase in Display: Unsupported");
_handle_esc_csi_ed(ty, ptr);
}
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@ -2557,43 +2597,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
break;
case 'J':
if (*b == '?')
{
b++;
arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
goto error;
WRN("Unsupported selected erase in display %d", arg);
ty->decoding_error = EINA_TRUE;
break;
}
_handle_esc_csi_decsed(ty, &b);
else
{
arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
goto error;
}
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 */:
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);
ty->decoding_error = EINA_TRUE;
}
_handle_esc_csi_ed(ty, &b);
break;
case 'K': // 0K erase to end of line, 1K erase from screen start to cursor, 2K erase all of line
if (*b == '?')

@ -0,0 +1,55 @@
#!/bin/sh
# fill space
for V in $(seq 0 50); do
printf '%s\n' "$V"
done
# 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
# 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'
# restrict cursor
printf '\033[?6h'
# move
printf '\033[10;30H'
# ED 0 (default) (Erase from the cursor to the end)
printf '\033[J'

@ -0,0 +1,55 @@
#!/bin/sh
# fill space
for V in $(seq 0 50); do
printf '%s\n' "$V"
done
# 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
# 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'
# restrict cursor
printf '\033[?6h'
# move
printf '\033[10;30H'
# ED 1 (Erase the beginning of the display through the cursor)
printf '\033[1J'

@ -0,0 +1,55 @@
#!/bin/sh
# fill space
for V in $(seq 0 50); do
printf '%s\n' "$V"
done
# 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
# 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'
# restrict cursor
printf '\033[?6h'
# move
printf '\033[10;30H'
# ED 2 (The complete display)
printf '\033[2J'

@ -0,0 +1,55 @@
#!/bin/sh
# fill space
for V in $(seq 0 50); do
printf '%s\n' "$V"
done
# 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
# 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'
# restrict cursor
printf '\033[?6h'
# move
printf '\033[10;30H'
# ED 3 (The display scrollback)
printf '\033[3J'

@ -0,0 +1,55 @@
#!/bin/sh
# fill space
for V in $(seq 0 50); do
printf '%s\n' "$V"
done
# 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
# 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'
# restrict cursor
printf '\033[?6h'
# move
printf '\033[10;30H'
# ED 4 nothing
printf '\033[4J'

@ -52,3 +52,8 @@ decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33
decic-decdc.sh 6d67999a7c5c771281ff2229cdbdda76
ich.sh 3bd7dfc4a7cbcdf0985cda5da46e07ec
deccra.sh 6a0846004c4effb9d5eb45b8044d5f7e
ed-0.sh 169d09249a920f95e5c9fc517d5f90a9
ed-1.sh 399897d5dd697adea2cc460ca6132826
ed-2.sh 82e7919a46fdea3a003143b41562b148
ed-3.sh 005871b7e4d63017c08a73ab34f99b14
ed-4.sh 574f37ac24ead26ef86c03d7dfae3152

Loading…
Cancel
Save