termptyesc: extract CBT handler to its own function + tests

This commit is contained in:
Boris Faure 2019-01-13 00:08:52 +01:00
parent bf3d3991cd
commit c1d030da0a
3 changed files with 46 additions and 20 deletions

View File

@ -2803,6 +2803,31 @@ _handle_esc_csi_ech(Termpty *ty, Eina_Unicode **ptr)
termpty_clear_line(ty, TERMPTY_CLR_END, arg);
}
static void
_handle_esc_csi_cbt(Termpty *ty, Eina_Unicode **ptr)
{
Eina_Unicode *b = *ptr;
int cx = ty->cursor_state.cx;
int arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
return;
DBG("CBT - Cursor Horizontal Backward Tabulation: %d", arg);
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
for (; arg > 0; arg--)
{
do
{
cx--;
}
while ((cx >= 0) && (!TAB_TEST(ty, cx)));
}
ty->cursor_state.cx = cx;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
}
static int
_handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
{
@ -2908,26 +2933,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
_handle_esc_csi_ech(ty, &b);
break;
case 'Z':
{
int cx = ty->cursor_state.cx;
arg = _csi_arg_get(ty, &b);
if (arg == -CSI_ARG_ERROR)
goto error;
DBG("Cursor Backward Tabulation (CBT): %d", arg);
TERMPTY_RESTRICT_FIELD(arg, 1, ty->w);
for (; arg > 0; arg--)
{
do
{
cx--;
}
while ((cx >= 0) && (!TAB_TEST(ty, cx)));
}
ty->cursor_state.cx = cx;
TERMPTY_RESTRICT_FIELD(ty->cursor_state.cx, 0, ty->w);
}
_handle_esc_csi_cbt(ty, &b);
break;
case '`': // HPA
arg = _csi_arg_get(ty, &b);

19
tests/cbt.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
# fill space with E
printf '\033#8'
# set color
printf '\033[46;31;3m'
# move to 0;0
printf '\033[H'
# set tabs
printf '\033H\033H\033[3C\033[W\033[4C\033[0W\033[5C\033H\033[6C\033H'
printf '\033[7C\033H\033[8C\033H\033[9C'
printf '\nTabs set:'
# show # on tabs
printf '\n#\t#\t#\t#\t#\t#\t#\t#\t#\t#\t#'
printf '\033[Z@'
printf '\n#\t#\t#\t#\t#\t#\t#\t#\t#\t#\t#'
printf '\033[0Z@'
printf '\n#\t#\t#\t#\t#\t#\t#\t#\t#\t#\t#'
printf '\033[3Z@'

View File

@ -67,3 +67,4 @@ ctc.sh d35eeacdb2e99f5ac8cc3c4e8d72f8b0
tbc.sh d0216e4056e5ab1cb4d411b6d6074785
ech.sh 57a3ff127abbb3efa4082fab7de59970
text_append_after_right_margin.sh 26b334188d39e2b12538a6ca91ca168c
cbt.sh 417cd352d3eba45d6016df67a0314444