aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2019-01-13 00:08:52 +0100
committerBoris Faure <billiob@gmail.com>2019-01-13 00:08:52 +0100
commitc1d030da0ac4f090fd060f9a9a665a4e75091313 (patch)
treeccdc690eefc03b8f283d3113dd390ef08036d920 /src
parentci: fix codecov script (diff)
downloadterminology-c1d030da0ac4f090fd060f9a9a665a4e75091313.tar.gz
termptyesc: extract CBT handler to its own function + tests
Diffstat (limited to 'src')
-rw-r--r--src/bin/termptyesc.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index e6e3fed..bf9bb0d 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -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);