billiob pushed a commit to branch master.

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

commit 3cafc4272d6b1600f323eb785e76a662bc7818f2
Author: Boris Faure <bo...@fau.re>
Date:   Thu Jul 6 20:17:47 2017 +0200

    feature: click-alt tries to handle wrapped CLI. Closes T5537
---
 src/bin/termptyops.c | 64 +++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 7635d0e..db069d7 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -477,24 +477,62 @@ termpty_cursor_copy(Termpty *ty, Eina_Bool save)
 void
 termpty_move_cursor(Termpty *ty, int cx, int cy)
 {
-   int vect;
+   int cur_cx = ty->cursor_state.cx;
+   int cur_cy = ty->cursor_state.cy;
+   Termcell *cells;
+   ssize_t wlen;
+   int n_to_down = 0;
+   int n_to_right = 0;
+
+   /* move Up or Down */
+   while (cur_cy != cy)
+     {
+        if (cur_cy < cy)
+          {
+             /* go down */
+             cells = termpty_cellrow_get(ty, cur_cy, &wlen);
+             assert(cells);
+             if (cells[wlen-1].att.autowrapped)
+               {
+                  n_to_right += ty->w;
+               }
+             else
+               {
+                  n_to_down++;
+               }
+             cur_cy++;
+          }
+        else
+          {
+             /* go up */
+             cells = termpty_cellrow_get(ty, cur_cy - 1, &wlen);
+             assert(cells);
+             if (cells[wlen-1].att.autowrapped)
+               {
+                  n_to_right -= ty->w;
+               }
+             else
+               {
+                  n_to_down--;
+               }
+             cur_cy--;
+          }
+     }
+
+   n_to_right += cx - cur_cx;
 
-   /* right/left */
-   vect = cx - ty->cursor_state.cx;
-   /* left */
-   for (; vect < 0; vect++)
-     termpty_write(ty, "\033[D", strlen("\033[D"));
    /* right */
-   for (; vect > 0; vect--)
+   for (; n_to_right > 0; n_to_right--)
      termpty_write(ty, "\033[C", strlen("\033[C"));
+   /* left */
+   for (; n_to_right < 0; n_to_right++)
+     termpty_write(ty, "\033[D", strlen("\033[D"));
 
-   /* up/down */
-   vect = cy - ty->cursor_state.cy;
-   /* up */
-   for (; vect < 0; vect++)
-     termpty_write(ty, "\033[A", strlen("\033[A"));
    /* down*/
-   for (; vect > 0; vect--)
+   for (; n_to_down > 0; n_to_down--)
      termpty_write(ty, "\033[B", strlen("\033[B"));
+   /* up */
+   for (; n_to_down < 0; n_to_down++)
+     termpty_write(ty, "\033[A", strlen("\033[A"));
 
 }

-- 


Reply via email to