billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=c1d030da0ac4f090fd060f9a9a665a4e75091313

commit c1d030da0ac4f090fd060f9a9a665a4e75091313
Author: Boris Faure <bill...@gmail.com>
Date:   Sun Jan 13 00:08:52 2019 +0100

    termptyesc: extract CBT handler to its own function + tests
---
 src/bin/termptyesc.c | 46 ++++++++++++++++++++++++++--------------------
 tests/cbt.sh         | 19 +++++++++++++++++++
 tests/tests.results  |  1 +
 3 files changed, 46 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);
diff --git a/tests/cbt.sh b/tests/cbt.sh
new file mode 100755
index 0000000..cab4a65
--- /dev/null
+++ b/tests/cbt.sh
@@ -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@'
diff --git a/tests/tests.results b/tests/tests.results
index 79ceed4..460ea37 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -67,3 +67,4 @@ ctc.sh d35eeacdb2e99f5ac8cc3c4e8d72f8b0
 tbc.sh d0216e4056e5ab1cb4d411b6d6074785
 ech.sh 57a3ff127abbb3efa4082fab7de59970
 text_append_after_right_margin.sh 26b334188d39e2b12538a6ca91ca168c
+cbt.sh 417cd352d3eba45d6016df67a0314444

-- 


Reply via email to