termptyesc: export EL handler to its own function + add tests

terminology-1.4
Boris Faure 4 years ago
parent 06abd7e9bc
commit 0ca634cd69
  1. 62
      src/bin/termptyesc.c
  2. 6
      src/bin/termptyops.h
  3. 74
      tests/el.sh
  4. 1
      tests/tests.results

@ -2533,6 +2533,37 @@ _handle_esc_csi_decsed(Termpty *ty, Eina_Unicode **ptr)
_handle_esc_csi_ed(ty, ptr);
}
static void
_handle_esc_csi_el(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;
DBG("EL - Erase in Line: %d", 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);
ty->decoding_error = EINA_TRUE;
}
}
static void
_handle_esc_csi_decsel(Termpty *ty, Eina_Unicode **ptr)
{
WRN("DECSEL - Selective Erase in Line: Unsupported");
_handle_esc_csi_el(ty, ptr);
}
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@ -2601,34 +2632,11 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
else
_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
case 'K':
if (*b == '?')
{
b++;
arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
goto error;
WRN("Unsupported selected erase in line %d", arg);
ty->decoding_error = EINA_TRUE;
break;
}
arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
goto error;
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);
ty->decoding_error = EINA_TRUE;
}
_handle_esc_csi_decsel(ty, &b);
else
_handle_esc_csi_el(ty, &b);
break;
case 'L': // insert N lines - cy
EINA_FALLTHROUGH;

@ -3,9 +3,9 @@
typedef enum _Termpty_Clear
{
TERMPTY_CLR_END,
TERMPTY_CLR_BEGIN,
TERMPTY_CLR_ALL
TERMPTY_CLR_END = 0,
TERMPTY_CLR_BEGIN = 1,
TERMPTY_CLR_ALL = 2
} Termpty_Clear;
void termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max);

@ -0,0 +1,74 @@
#!/bin/sh
# 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'
printf '\033[3;30H#'
# move
printf '\033[4;30H#\033[4;30H'
# EL 0 -> Erase Line Right
printf '\033[0K'
# move
printf '\033[5;30H#\033[5;30H'
# EL 0 (default) -> Erase Line Right
printf '\033[K'
printf '\033[6;30H#'
# move
printf '\033[7;30H#\033[7;30H'
# EL 1 -> Erase Line Left
printf '\033[1K'
printf '\033[8;30H#'
# move
printf '\033[9;30H#\033[9;30H'
# EL 2 -> Erase Complete Line
printf '\033[2K'
printf '\033[10;30H#'
# move
printf '\033[11;30H#\033[11;30H'
# EL 3 -> Nothing
printf '\033[3K'

@ -57,3 +57,4 @@ ed-1.sh 399897d5dd697adea2cc460ca6132826
ed-2.sh 82e7919a46fdea3a003143b41562b148
ed-3.sh 005871b7e4d63017c08a73ab34f99b14
ed-4.sh 574f37ac24ead26ef86c03d7dfae3152
el.sh abca9d5e5990bed6bd72a7ab9f72b849

Loading…
Cancel
Save