summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <boris@fau.re>2017-07-06 20:17:47 +0200
committerBoris Faure <boris@fau.re>2017-07-06 20:17:47 +0200
commit3cafc4272d6b1600f323eb785e76a662bc7818f2 (patch)
treed39de097ec3cdf665ebeb2720fa033b72f113dd4
parentde3890dad36dcaa1869b13dc7590f4e3c0e81df3 (diff)
feature: click-alt tries to handle wrapped CLI. Closes T5537
-rw-r--r--src/bin/termptyops.c64
1 files 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)
477void 477void
478termpty_move_cursor(Termpty *ty, int cx, int cy) 478termpty_move_cursor(Termpty *ty, int cx, int cy)
479{ 479{
480 int vect; 480 int cur_cx = ty->cursor_state.cx;
481 int cur_cy = ty->cursor_state.cy;
482 Termcell *cells;
483 ssize_t wlen;
484 int n_to_down = 0;
485 int n_to_right = 0;
486
487 /* move Up or Down */
488 while (cur_cy != cy)
489 {
490 if (cur_cy < cy)
491 {
492 /* go down */
493 cells = termpty_cellrow_get(ty, cur_cy, &wlen);
494 assert(cells);
495 if (cells[wlen-1].att.autowrapped)
496 {
497 n_to_right += ty->w;
498 }
499 else
500 {
501 n_to_down++;
502 }
503 cur_cy++;
504 }
505 else
506 {
507 /* go up */
508 cells = termpty_cellrow_get(ty, cur_cy - 1, &wlen);
509 assert(cells);
510 if (cells[wlen-1].att.autowrapped)
511 {
512 n_to_right -= ty->w;
513 }
514 else
515 {
516 n_to_down--;
517 }
518 cur_cy--;
519 }
520 }
521
522 n_to_right += cx - cur_cx;
481 523
482 /* right/left */
483 vect = cx - ty->cursor_state.cx;
484 /* left */
485 for (; vect < 0; vect++)
486 termpty_write(ty, "\033[D", strlen("\033[D"));
487 /* right */ 524 /* right */
488 for (; vect > 0; vect--) 525 for (; n_to_right > 0; n_to_right--)
489 termpty_write(ty, "\033[C", strlen("\033[C")); 526 termpty_write(ty, "\033[C", strlen("\033[C"));
527 /* left */
528 for (; n_to_right < 0; n_to_right++)
529 termpty_write(ty, "\033[D", strlen("\033[D"));
490 530
491 /* up/down */
492 vect = cy - ty->cursor_state.cy;
493 /* up */
494 for (; vect < 0; vect++)
495 termpty_write(ty, "\033[A", strlen("\033[A"));
496 /* down*/ 531 /* down*/
497 for (; vect > 0; vect--) 532 for (; n_to_down > 0; n_to_down--)
498 termpty_write(ty, "\033[B", strlen("\033[B")); 533 termpty_write(ty, "\033[B", strlen("\033[B"));
534 /* up */
535 for (; n_to_down < 0; n_to_down++)
536 termpty_write(ty, "\033[A", strlen("\033[A"));
499 537
500} 538}