billiob pushed a commit to branch master.

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

commit feb7495fbb9a221367d77f39da3557dd74fa1d14
Author: Boris Faure <[email protected]>
Date:   Sun Dec 9 17:46:14 2018 +0100

    termptyesc: DSR-CPR takes cursor restriction into account + test
---
 src/bin/termptyesc.c | 58 ++++++++++++++++++++++++++++++----------------------
 tests/dsr-cpr.sh     | 40 ++++++++++++++++++++++++++++++++++++
 tests/tests.results  |  1 +
 3 files changed, 74 insertions(+), 25 deletions(-)

diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index fb78cc5..23adab5 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -956,6 +956,7 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
 {
    int arg, len;
    char bf[32];
+   Eina_Bool question_mark = EINA_FALSE;
 
    if (*b == '>')
      {
@@ -964,35 +965,42 @@ _handle_esc_csi_dsr(Termpty *ty, Eina_Unicode *b)
      }
    if (*b == '?')
      {
+        question_mark = EINA_TRUE;
         b++;
-        arg = _csi_arg_get(&b);
-        switch (arg)
-          {
-           case 6:
-              len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
-                             ty->cursor_state.cy + 1,
-                             ty->cursor_state.cx + 1);
-              termpty_write(ty, bf, len);
-              break;
-           default:
-              WRN("unhandled DSR (dec specific) %d", arg);
-              break;
-          }
      }
-   else
+   arg = _csi_arg_get(&b);
+   switch (arg)
      {
-        arg = _csi_arg_get(&b);
-        switch (arg)
-          {
-           case 6:
-              len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
-                             ty->cursor_state.cy + 1, ty->cursor_state.cx + 1);
+      case 6:
+           {
+              int cx = ty->cursor_state.cx,
+                  cy = ty->cursor_state.cy;
+              if (ty->termstate.restrict_cursor)
+                {
+                   if (ty->termstate.top_margin)
+                     cy -= ty->termstate.top_margin;
+                   if (ty->termstate.left_margin)
+                     cx -= ty->termstate.left_margin;
+                }
+              if (question_mark)
+                {
+                   len = snprintf(bf, sizeof(bf), "\033[?%d;%d;1R",
+                                  cy + 1,
+                                  cx + 1);
+                }
+              else
+                {
+                   len = snprintf(bf, sizeof(bf), "\033[%d;%dR",
+                                  cy + 1,
+                                  cx + 1);
+                }
               termpty_write(ty, bf, len);
-              break;
-           default:
-              WRN("unhandled DSR %d", arg);
-              break;
-          }
+           }
+         break;
+      default:
+         WRN("unhandled DSR (dec specific: %s) %d",
+             (question_mark)? "yes": "no", arg);
+         break;
      }
 }
 
diff --git a/tests/dsr-cpr.sh b/tests/dsr-cpr.sh
new file mode 100755
index 0000000..b08c03b
--- /dev/null
+++ b/tests/dsr-cpr.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# fill space with E
+printf '\033#8'
+#set color
+printf '\033[46;31;3m'
+
+# cursor to 7,4
+printf '\033[7;4H'
+# Request cursor position
+printf '\033[6n'
+# Request cursor position (dec)
+printf '\033[?6n'
+
+sleep 1
+
+# set top/bottom margins:
+printf '\033[10;20r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[5;15s'
+
+# cursor to 17,14
+printf '\033[17;14H'
+
+# Request cursor position
+printf '\033[6n'
+# Request cursor position (dec)
+printf '\033[?6n'
+
+sleep 1
+
+# restrict cursor
+printf '\033[?6h'
+
+# Request cursor position
+printf '\033[6n'
+# Request cursor position (dec)
+printf '\033[?6n'
diff --git a/tests/tests.results b/tests/tests.results
index c9a8fe1..9bad340 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -17,3 +17,4 @@ tabs.sh 960b74686e23e8e39c3446768b9efc75
 xterm-osc-0-title-icon.sh cb5080cc1dbc23b553b62fbdc8cbdf68
 xterm-osc-1-icon.sh 9202db6e81ce810f007035770934fecb
 xterm-osc-2-title.sh 49a058f1813bdd64faab1cf1af3ebe09
+dsr-cpr.sh 5a778fd856455475e695e5469e69d227

-- 


Reply via email to