billiob pushed a commit to branch master.

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

commit fee45b5492bce86322e2c89b5466b9a246af6ad0
Author: Boris Faure <[email protected]>
Date:   Sat Dec 29 22:13:58 2018 +0100

    termptyesc: DECCRARA/DECRARA when not in rectangle mode + tests
---
 src/bin/termptyesc.c                               | 293 +++++++++++++++++----
 ...> deccara-no-rectangular-no-restrict-cursor.sh} |  33 ++-
 ...h => deccara-no-rectangular-restrict-cursor.sh} |  34 +--
 ...> decrara-no-rectangular-no-restrict-cursor.sh} |  31 ++-
 ...h => decrara-no-rectangular-restrict-cursor.sh} |  31 ++-
 tests/decrara-rectangular-no-restrict-cursor.sh    |   4 +-
 tests/decrara-rectangular-restrict-cursor.sh       |   4 +-
 tests/tests.results                                |   4 +
 8 files changed, 326 insertions(+), 108 deletions(-)

diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 7ee6281..a9dba0b 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -1514,6 +1514,80 @@ _clean_up_rect_coordinates(Termpty *ty,
    return 0;
 }
 
+static int
+_clean_up_from_to_coordinates(Termpty *ty,
+                              int *top_ptr,
+                              int *left_ptr,
+                              int *bottom_ptr,
+                              int *right_ptr,
+                              int *left_border,
+                              int *right_border)
+{
+   int top = *top_ptr;
+   int left = *left_ptr;
+   int bottom = *bottom_ptr;
+   int right = *right_ptr;
+
+   TERMPTY_RESTRICT_FIELD(top, 1, ty->h);
+   if (ty->termstate.restrict_cursor)
+     {
+        top += ty->termstate.top_margin;
+        if (ty->termstate.bottom_margin && top >= ty->termstate.bottom_margin)
+          top = ty->termstate.bottom_margin;
+     }
+   top--;
+
+   TERMPTY_RESTRICT_FIELD(left, 1, ty->w);
+   if (ty->termstate.restrict_cursor)
+     {
+        left += ty->termstate.left_margin;
+        if (ty->termstate.right_margin && left >= ty->termstate.right_margin)
+          left = ty->termstate.right_margin;
+     }
+   left--;
+
+   if (right < 1)
+     right = ty->w;
+   if (ty->termstate.restrict_cursor)
+     {
+        right += ty->termstate.left_margin;
+        if (ty->termstate.right_margin && right >= ty->termstate.right_margin)
+          right = ty->termstate.right_margin;
+     }
+   if (right > ty->w)
+     right = ty->w;
+
+   if (bottom < 1)
+     bottom = ty->h;
+   if (ty->termstate.restrict_cursor)
+     {
+        bottom += ty->termstate.top_margin;
+        if (ty->termstate.bottom_margin && bottom >= 
ty->termstate.bottom_margin)
+          bottom = ty->termstate.bottom_margin;
+     }
+   bottom--;
+   if (bottom > ty->h)
+     bottom = ty->h - 1;
+
+   if ((bottom == top) && (right < left))
+     return -1;
+
+   *left_border = 0;
+   *right_border = ty->w-1;
+   if (ty->termstate.restrict_cursor)
+     {
+        *left_border = ty->termstate.left_margin;
+        *right_border = ty->termstate.right_margin;
+     }
+
+   *top_ptr = top;
+   *left_ptr = left;
+   *bottom_ptr = bottom;
+   *right_ptr = right;
+
+   return 0;
+}
+
 static void
 _handle_esc_csi_decfra(Termpty *ty, Eina_Unicode **b)
 {
@@ -1550,20 +1624,52 @@ _handle_esc_csi_decfra(Termpty *ty, Eina_Unicode **b)
      }
 }
 
+static void
+_deccara(Termcell *cells, int len,
+         Eina_Bool set_bold, Eina_Bool reset_bold,
+         Eina_Bool set_underline, Eina_Bool reset_underline,
+         Eina_Bool set_blink, Eina_Bool reset_blink,
+         Eina_Bool set_inverse, Eina_Bool reset_inverse)
+{
+   int i;
+
+   for (i = 0; i < len; i++)
+     {
+        Termatt * att = &cells[i].att;
+        if (set_bold)
+          att->bold = 1;
+        if (set_underline)
+          att->underline = 1;
+        if (set_blink)
+          att->blink = 1;
+        if (set_inverse)
+          att->inverse = 1;
+        if (reset_bold)
+          att->bold = 0;
+        if (reset_underline)
+          att->underline = 0;
+        if (reset_blink)
+          att->blink = 0;
+        if (reset_inverse)
+          att->inverse = 0;
+     }
+}
+
 static void
 _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode **ptr,
                         const Eina_Unicode * const end)
 {
    Eina_Unicode *b = *ptr;
+   Termcell *cells;
    int top;
    int left;
    int bottom;
    int right;
-   int i, len;
+   int len;
    Eina_Bool set_bold = EINA_FALSE, reset_bold = EINA_FALSE;
    Eina_Bool set_underline = EINA_FALSE, reset_underline = EINA_FALSE;
    Eina_Bool set_blink = EINA_FALSE, reset_blink = EINA_FALSE;
-   Eina_Bool set_reverse = EINA_FALSE, reset_reverse = EINA_FALSE;
+   Eina_Bool set_inverse = EINA_FALSE, reset_inverse = EINA_FALSE;
 
    top = _csi_arg_get(ty, &b);
    left = _csi_arg_get(ty, &b);
@@ -1588,8 +1694,8 @@ _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode **ptr,
            case -CSI_ARG_NO_VALUE:
               EINA_FALLTHROUGH;
            case 0:
-              set_bold = set_underline = set_blink = set_reverse = EINA_FALSE;
-              reset_bold = reset_underline = reset_blink = reset_reverse = 
EINA_TRUE;
+              set_bold = set_underline = set_blink = set_inverse = EINA_FALSE;
+              reset_bold = reset_underline = reset_blink = reset_inverse = 
EINA_TRUE;
               break;
            case 1:
               set_bold = EINA_TRUE;
@@ -1604,8 +1710,8 @@ _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode **ptr,
               reset_blink = EINA_FALSE;
               break;
            case 7:
-              set_reverse = EINA_TRUE;
-              reset_reverse = EINA_FALSE;
+              set_inverse = EINA_TRUE;
+              reset_inverse = EINA_FALSE;
               break;
            case 22:
               set_bold = EINA_FALSE;
@@ -1620,8 +1726,8 @@ _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode **ptr,
               reset_blink = EINA_TRUE;
               break;
            case 27:
-              set_reverse = EINA_FALSE;
-              reset_reverse = EINA_TRUE;
+              set_inverse = EINA_FALSE;
+              reset_inverse = EINA_TRUE;
               break;
            default:
               WRN("Invalid change attribute [%i]", arg);
@@ -1630,47 +1736,104 @@ _handle_esc_csi_deccara(Termpty *ty, Eina_Unicode 
**ptr,
           }
      }
 
-   if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0)
-     return;
+   if (ty->termstate.sace_rectangular)
+     {
+        if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0)
+          return;
 
-   len = right - left;
+        len = right - left;
 
-   for (; top <= bottom; top++)
+        for (; top <= bottom; top++)
+          {
+             cells = &(TERMPTY_SCREEN(ty, left, top));
+             _deccara(cells, len, set_bold, reset_bold, set_underline,
+                      reset_underline, set_blink, reset_blink, set_inverse,
+                      reset_inverse);
+          }
+     }
+   else
      {
-        Termcell *cells = &(TERMPTY_SCREEN(ty, left, top));
-        for (i = 0; i < len; i++)
-          {
-             Termatt * att = &cells[i].att;
-             if (set_bold)
-               att->bold = 1;
-             if (set_underline)
-               att->underline = 1;
-             if (set_blink)
-               att->blink = 1;
-             if (set_reverse)
-               att->inverse = 1;
-             if (reset_bold)
-               att->bold = 0;
-             if (reset_underline)
-               att->underline = 0;
-             if (reset_blink)
-               att->blink = 0;
-             if (reset_reverse)
-               att->inverse = 0;
+        int left_border = 0;
+        int right_border = ty->w - 1;
+
+        if (_clean_up_from_to_coordinates(ty, &top, &left, &bottom, &right,
+                                          &left_border, &right_border) < 0)
+          return;
+        if (top == bottom)
+          {
+             cells = &(TERMPTY_SCREEN(ty, left, top));
+             len = right - left;
+             _deccara(cells, len, set_bold, reset_bold,
+                      set_underline, reset_underline,
+                      set_blink, reset_blink,
+                      set_inverse, reset_inverse);
+          }
+        else
+          {
+             /* First line */
+             cells = &(TERMPTY_SCREEN(ty, left, top));
+             len = right_border - left;
+             _deccara(cells, len, set_bold, reset_bold,
+                      set_underline, reset_underline,
+                      set_blink, reset_blink,
+                      set_inverse, reset_inverse);
+
+             /* Middle */
+             len = right_border - left_border;
+             for (top = top + 1; top < bottom; top++)
+               {
+                  cells = &(TERMPTY_SCREEN(ty, left_border, top));
+                  _deccara(cells, len, set_bold, reset_bold,
+                           set_underline, reset_underline,
+                           set_blink, reset_blink,
+                           set_inverse, reset_inverse);
+               }
+
+             /* Last line */
+             cells = &(TERMPTY_SCREEN(ty, left_border, bottom));
+             len = right - left_border;
+             _deccara(cells, len, set_bold, reset_bold,
+                      set_underline, reset_underline,
+                      set_blink, reset_blink,
+                      set_inverse, reset_inverse);
           }
      }
 }
 
+static void
+_decrara(Termcell *cells, int len,
+         Eina_Bool reverse_bold,
+         Eina_Bool reverse_underline,
+         Eina_Bool reverse_blink,
+         Eina_Bool reverse_inverse)
+{
+   int i;
+
+   for (i = 0; i < len; i++)
+     {
+        Termatt * att = &cells[i].att;
+        if (reverse_bold)
+          att->bold = !att->bold;
+        if (reverse_underline)
+          att->underline = !att->underline;
+        if (reverse_blink)
+          att->blink = !att->blink;
+        if (reverse_inverse)
+          att->inverse = !att->inverse;
+     }
+}
+
 static void
 _handle_esc_csi_decrara(Termpty *ty, Eina_Unicode **ptr,
                         const Eina_Unicode * const end)
 {
    Eina_Unicode *b = *ptr;
+   Termcell *cells;
    int top;
    int left;
    int bottom;
    int right;
-   int i, len;
+   int len;
    Eina_Bool reverse_bold = EINA_FALSE;
    Eina_Bool reverse_underline = EINA_FALSE;
    Eina_Bool reverse_blink = EINA_FALSE;
@@ -1720,25 +1883,57 @@ _handle_esc_csi_decrara(Termpty *ty, Eina_Unicode **ptr,
           }
      }
 
-   if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0)
-     return;
+   if (ty->termstate.sace_rectangular)
+     {
+        if (_clean_up_rect_coordinates(ty, &top, &left, &bottom, &right) < 0)
+          return;
 
-   len = right - left;
+        len = right - left;
 
-   for (; top <= bottom; top++)
+        for (; top <= bottom; top++)
+          {
+             cells = &(TERMPTY_SCREEN(ty, left, top));
+             _decrara(cells, len, reverse_bold, reverse_underline,
+                      reverse_blink, reverse_inverse);
+          }
+     }
+   else
      {
-        Termcell *cells = &(TERMPTY_SCREEN(ty, left, top));
-        for (i = 0; i < len; i++)
-          {
-             Termatt * att = &cells[i].att;
-             if (reverse_bold)
-               att->bold = !att->bold;
-             if (reverse_underline)
-               att->underline = !att->underline;
-             if (reverse_blink)
-               att->blink = !att->blink;
-             if (reverse_inverse)
-               att->inverse = !att->inverse;
+        int left_border = 0;
+        int right_border = ty->w - 1;
+
+        if (_clean_up_from_to_coordinates(ty, &top, &left, &bottom, &right,
+                                          &left_border, &right_border) < 0)
+          return;
+        if (top == bottom)
+          {
+             cells = &(TERMPTY_SCREEN(ty, left, top));
+             len = right - left;
+             _decrara(cells, len, reverse_bold, reverse_underline,
+                      reverse_blink, reverse_inverse);
+          }
+        else
+          {
+             /* First line */
+             cells = &(TERMPTY_SCREEN(ty, left, top));
+             len = right_border - left;
+             _decrara(cells, len, reverse_bold, reverse_underline,
+                      reverse_blink, reverse_inverse);
+
+             /* Middle */
+             len = right_border - left_border;
+             for (top = top + 1; top < bottom; top++)
+               {
+                  cells = &(TERMPTY_SCREEN(ty, left_border, top));
+                  _decrara(cells, len, reverse_bold, reverse_underline,
+                           reverse_blink, reverse_inverse);
+               }
+
+             /* Last line */
+             cells = &(TERMPTY_SCREEN(ty, left_border, bottom));
+             len = right - left_border;
+             _decrara(cells, len, reverse_bold, reverse_underline,
+                      reverse_blink, reverse_inverse);
           }
      }
 }
diff --git a/tests/decrara-rectangular-no-restrict-cursor.sh 
b/tests/deccara-no-rectangular-no-restrict-cursor.sh
similarity index 60%
copy from tests/decrara-rectangular-no-restrict-cursor.sh
copy to tests/deccara-no-rectangular-no-restrict-cursor.sh
index 982feba..7072dc8 100755
--- a/tests/decrara-rectangular-no-restrict-cursor.sh
+++ b/tests/deccara-no-rectangular-no-restrict-cursor.sh
@@ -33,26 +33,31 @@ done
 # move to 0; 0
 printf '\033[H'
 
-# set top/bottom margins:
-printf '\033[5;20r'
+# no rectangular modifications
+printf '\033[1*x'
 
-# force rectangular modifications
-printf '\033[2*x'
+# set top/bottom margins:
+printf '\033[1;24r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[20;55s'
 
 # reset all
-printf '\033[1;10;80;15;0\044t'
+printf '\033[2;10;4;65;0\044r'
 
 # reset all
-printf '\033[1;20;80;25;1;4;5;7\044t'
+printf '\033[6;20;8;55;1;4;5;7\044r'
 
-# reverse bold/blink
-printf '\033[1;30;80;35;1;5\044t'
+# set bold/blink
+printf '\033[10;63;12;55;1;5\044r'
 
-# reverse bold/underline
-printf '\033[1;40;80;45;1;4\044t'
+# set bold/underline
+printf '\033[14;8;16;45;1;4\044r'
 
-# reverse blink/inverse
-printf '\033[1;50;80;55;5;7\044t'
+# set underline/inverse
+# @xtermbug
+printf '\033[18;6;20;5;4;7\044r'
 
-# reverse underline/inverse
-printf '\033[1;60;80;65;4;7;0\044t'
+# set underline/inverse
+printf '\033[21;6;21;65;4;7\044r'
diff --git a/tests/decrara-rectangular-restrict-cursor.sh 
b/tests/deccara-no-rectangular-restrict-cursor.sh
similarity index 62%
copy from tests/decrara-rectangular-restrict-cursor.sh
copy to tests/deccara-no-rectangular-restrict-cursor.sh
index d5f8f9a..8354759 100755
--- a/tests/decrara-rectangular-restrict-cursor.sh
+++ b/tests/deccara-no-rectangular-restrict-cursor.sh
@@ -33,29 +33,33 @@ done
 # move to 0; 0
 printf '\033[H'
 
-# set top/bottom margins:
-printf '\033[5;20r'
+# no rectangular modifications
+printf '\033[1*x'
 
+# set top/bottom margins:
+printf '\033[1;24r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[20;55s'
 # restrict cursor
 printf '\033[?6h'
 
-# force rectangular modifications
-printf '\033[2*x'
-
 # reset all
-printf '\033[1;10;80;15;0\044t'
+printf '\033[2;10;4;65;0\044r'
 
 # reset all
-printf '\033[1;20;80;25;1;4;5;7\044t'
+printf '\033[6;20;8;55;1;4;5;7\044r'
 
-# reverse bold/blink
-printf '\033[1;30;80;35;1;5\044t'
+# set bold/blink
+printf '\033[10;63;12;55;1;5\044r'
 
-# reverse bold/underline
-printf '\033[1;40;80;45;1;4\044t'
+# set bold/underline
+printf '\033[14;8;16;45;1;4\044r'
 
-# reverse blink/inverse
-printf '\033[1;50;80;55;5;7\044t'
+# set underline/inverse
+# @xtermbug
+printf '\033[18;6;20;5;4;7\044r'
 
-# reverse underline/inverse
-printf '\033[1;60;80;65;4;7;0\044t'
+# set underline/inverse
+printf '\033[21;6;21;65;4;7\044r'
diff --git a/tests/decrara-rectangular-no-restrict-cursor.sh 
b/tests/decrara-no-rectangular-no-restrict-cursor.sh
similarity index 64%
copy from tests/decrara-rectangular-no-restrict-cursor.sh
copy to tests/decrara-no-rectangular-no-restrict-cursor.sh
index 982feba..b1b99ff 100755
--- a/tests/decrara-rectangular-no-restrict-cursor.sh
+++ b/tests/decrara-no-rectangular-no-restrict-cursor.sh
@@ -33,26 +33,31 @@ done
 # move to 0; 0
 printf '\033[H'
 
-# set top/bottom margins:
-printf '\033[5;20r'
+# no rectangular modifications
+printf '\033[1*x'
 
-# force rectangular modifications
-printf '\033[2*x'
+# set top/bottom margins:
+printf '\033[1;24r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[20;55s'
 
-# reset all
-printf '\033[1;10;80;15;0\044t'
+# reverse all
+printf '\033[2;10;4;65;0\044t'
 
-# reset all
-printf '\033[1;20;80;25;1;4;5;7\044t'
+# reverse all
+printf '\033[6;20;8;55;1;4;5;7\044t'
 
 # reverse bold/blink
-printf '\033[1;30;80;35;1;5\044t'
+printf '\033[10;63;12;55;1;5\044t'
 
 # reverse bold/underline
-printf '\033[1;40;80;45;1;4\044t'
+printf '\033[14;8;16;45;1;4\044t'
 
-# reverse blink/inverse
-printf '\033[1;50;80;55;5;7\044t'
+# reverse underline/inverse
+# @xtermbug
+printf '\033[18;6;20;5;4;7\044t'
 
 # reverse underline/inverse
-printf '\033[1;60;80;65;4;7;0\044t'
+printf '\033[21;6;21;65;4;7\044t'
diff --git a/tests/decrara-rectangular-restrict-cursor.sh 
b/tests/decrara-no-rectangular-restrict-cursor.sh
similarity index 65%
copy from tests/decrara-rectangular-restrict-cursor.sh
copy to tests/decrara-no-rectangular-restrict-cursor.sh
index d5f8f9a..345b46e 100755
--- a/tests/decrara-rectangular-restrict-cursor.sh
+++ b/tests/decrara-no-rectangular-restrict-cursor.sh
@@ -33,29 +33,34 @@ done
 # move to 0; 0
 printf '\033[H'
 
+# no rectangular modifications
+printf '\033[1*x'
+
 # set top/bottom margins:
-printf '\033[5;20r'
+printf '\033[1;24r'
+# allow left/right margins
+printf '\033[?69h'
+# set left/right margins:
+printf '\033[20;55s'
 
 # restrict cursor
 printf '\033[?6h'
 
-# force rectangular modifications
-printf '\033[2*x'
-
-# reset all
-printf '\033[1;10;80;15;0\044t'
+# reverse all
+printf '\033[2;10;4;65;0\044t'
 
-# reset all
-printf '\033[1;20;80;25;1;4;5;7\044t'
+# reverse all
+printf '\033[6;20;8;55;1;4;5;7\044t'
 
 # reverse bold/blink
-printf '\033[1;30;80;35;1;5\044t'
+printf '\033[10;63;12;55;1;5\044t'
 
 # reverse bold/underline
-printf '\033[1;40;80;45;1;4\044t'
+printf '\033[14;8;16;45;1;4\044t'
 
-# reverse blink/inverse
-printf '\033[1;50;80;55;5;7\044t'
+# reverse underline/inverse
+# @xtermbug
+printf '\033[18;6;20;5;4;7\044t'
 
 # reverse underline/inverse
-printf '\033[1;60;80;65;4;7;0\044t'
+printf '\033[21;6;21;65;4;7\044t'
diff --git a/tests/decrara-rectangular-no-restrict-cursor.sh 
b/tests/decrara-rectangular-no-restrict-cursor.sh
index 982feba..1f1d513 100755
--- a/tests/decrara-rectangular-no-restrict-cursor.sh
+++ b/tests/decrara-rectangular-no-restrict-cursor.sh
@@ -39,10 +39,10 @@ printf '\033[5;20r'
 # force rectangular modifications
 printf '\033[2*x'
 
-# reset all
+# reverse all
 printf '\033[1;10;80;15;0\044t'
 
-# reset all
+# reverse all
 printf '\033[1;20;80;25;1;4;5;7\044t'
 
 # reverse bold/blink
diff --git a/tests/decrara-rectangular-restrict-cursor.sh 
b/tests/decrara-rectangular-restrict-cursor.sh
index d5f8f9a..1555809 100755
--- a/tests/decrara-rectangular-restrict-cursor.sh
+++ b/tests/decrara-rectangular-restrict-cursor.sh
@@ -42,10 +42,10 @@ printf '\033[?6h'
 # force rectangular modifications
 printf '\033[2*x'
 
-# reset all
+# reverse all
 printf '\033[1;10;80;15;0\044t'
 
-# reset all
+# reverse all
 printf '\033[1;20;80;25;1;4;5;7\044t'
 
 # reverse bold/blink
diff --git a/tests/tests.results b/tests/tests.results
index 856cd01..aeff779 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -43,5 +43,9 @@ decbi.sh 8153bff12a0d529cb8ba0dbff036a1ee
 decfi.sh e93690447902b923d3d9d2ae72a31de4
 deccara-rectangular-no-restrict-cursor.sh 0d04ff5f4a266917528ff8d17846c18a
 deccara-rectangular-restrict-cursor.sh 9f23ac6a3423ba8bf7b8af5116e2843b
+deccara-no-rectangular-no-restrict-cursor.sh 692da353130f5fdaffc4e62a9102147c
+deccara-no-rectangular-restrict-cursor.sh eaa1a1f3e288fec06b917b1f953629c6
 decrara-rectangular-no-restrict-cursor.sh be9836ff18eafb90795faecc042f34d6
 decrara-rectangular-restrict-cursor.sh e98723f8f749e4902f7f4aaa677b85d6
+decrara-no-rectangular-no-restrict-cursor.sh c375dd5d6538aff4c920b022f32f4ab0
+decrara-no-rectangular-restrict-cursor.sh 815a848844cf7ea33d60e71948346a33

-- 


Reply via email to