termptyesc: extract ICH to its own function and add tests
This commit is contained in:
parent
12cc6aaf42
commit
6661719829
|
@ -2193,6 +2193,53 @@ _handle_esc_csi_decdc(Termpty *ty, Eina_Unicode **b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_handle_esc_csi_ich(Termpty *ty, Eina_Unicode **ptr)
|
||||||
|
{
|
||||||
|
Eina_Unicode blank[1] = { ' ' };
|
||||||
|
Eina_Unicode *b = *ptr;
|
||||||
|
int arg = _csi_arg_get(ty, &b);
|
||||||
|
int i;
|
||||||
|
int old_insert = ty->termstate.insert;
|
||||||
|
int old_cx = ty->cursor_state.cx;
|
||||||
|
int max = ty->w;
|
||||||
|
|
||||||
|
if (arg == -CSI_ARG_ERROR)
|
||||||
|
return;
|
||||||
|
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
|
||||||
|
|
||||||
|
DBG("ICH - Insert %d Characters", arg);
|
||||||
|
|
||||||
|
if (ty->termstate.lr_margins)
|
||||||
|
{
|
||||||
|
if ((ty->termstate.left_margin)
|
||||||
|
&& (ty->cursor_state.cx < ty->termstate.left_margin))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ty->termstate.right_margin)
|
||||||
|
{
|
||||||
|
if (ty->cursor_state.cx >= ty->termstate.right_margin)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
max = ty->termstate.right_margin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ty->cursor_state.cx + arg > max)
|
||||||
|
{
|
||||||
|
arg = max - ty->cursor_state.cx;
|
||||||
|
}
|
||||||
|
|
||||||
|
ty->termstate.wrapnext = 0;
|
||||||
|
ty->termstate.insert = 1;
|
||||||
|
for (i = 0; i < arg; i++)
|
||||||
|
termpty_text_append(ty, blank, 1);
|
||||||
|
ty->termstate.insert = old_insert;
|
||||||
|
ty->cursor_state.cx = old_cx;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
{
|
{
|
||||||
|
@ -2223,26 +2270,9 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
|
||||||
switch (*cc)
|
switch (*cc)
|
||||||
{
|
{
|
||||||
/* sorted by ascii value */
|
/* sorted by ascii value */
|
||||||
case '@': // insert N blank chars (ICH)
|
case '@':
|
||||||
/* TODO: SL */
|
/* TODO: SL */
|
||||||
arg = _csi_arg_get(ty, &b);
|
_handle_esc_csi_ich(ty, &b);
|
||||||
if (arg == -CSI_ARG_ERROR)
|
|
||||||
goto error;
|
|
||||||
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w * ty->h);
|
|
||||||
DBG("insert %d blank chars", arg);
|
|
||||||
{
|
|
||||||
int pi = ty->termstate.insert;
|
|
||||||
Eina_Unicode blank[1] = { ' ' };
|
|
||||||
int cx = ty->cursor_state.cx;
|
|
||||||
|
|
||||||
ty->termstate.wrapnext = 0;
|
|
||||||
ty->termstate.insert = 1;
|
|
||||||
for (i = 0; i < arg; i++)
|
|
||||||
termpty_text_append(ty, blank, 1);
|
|
||||||
ty->termstate.insert = pi;
|
|
||||||
ty->cursor_state.cx = cx;
|
|
||||||
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'A': // cursor up N (CUU)
|
case 'A': // cursor up N (CUU)
|
||||||
/* TODO: SR */
|
/* TODO: SR */
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
#!/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'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[3;60H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[200@'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[4;12H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[13@'
|
||||||
|
|
||||||
|
# set top/bottom margins:
|
||||||
|
printf '\033[3;20r'
|
||||||
|
# allow left/right margins
|
||||||
|
printf '\033[?69h'
|
||||||
|
# set left/right margins:
|
||||||
|
printf '\033[5;75s'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[20;70H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[200@'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[0;70H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[200@'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[2;4H'
|
||||||
|
# do not insert spaces, out of left/right margins
|
||||||
|
printf '\033[200@'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[2;76H'
|
||||||
|
# do not insert spaces, out of left/right margins
|
||||||
|
printf '\033[200@'
|
||||||
|
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[7;5H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[20@'
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[7;75H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[20@'
|
||||||
|
|
||||||
|
# WITH MARGINS ENFORCED
|
||||||
|
|
||||||
|
# set top/bottom margins:
|
||||||
|
printf '\033[3;10r'
|
||||||
|
# allow left/right margins
|
||||||
|
printf '\033[?69h'
|
||||||
|
# set left/right margins:
|
||||||
|
printf '\033[5;60s'
|
||||||
|
|
||||||
|
# restrict cursor
|
||||||
|
printf '\033[?6h'
|
||||||
|
|
||||||
|
|
||||||
|
# move
|
||||||
|
printf '\033[8;50H'
|
||||||
|
# insert spaces
|
||||||
|
printf '\033[200@'
|
|
@ -50,3 +50,4 @@ decrara-rectangular-restrict-cursor.sh e98723f8f749e4902f7f4aaa677b85d6
|
||||||
decrara-no-rectangular-no-restrict-cursor.sh c375dd5d6538aff4c920b022f32f4ab0
|
decrara-no-rectangular-no-restrict-cursor.sh c375dd5d6538aff4c920b022f32f4ab0
|
||||||
decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33
|
decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33
|
||||||
decic-decdc.sh 6d67999a7c5c771281ff2229cdbdda76
|
decic-decdc.sh 6d67999a7c5c771281ff2229cdbdda76
|
||||||
|
ich.sh fe1bfee25582f37a27665af1f66513df
|
||||||
|
|
Loading…
Reference in New Issue