aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/termptyops.c
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 /src/bin/termptyops.c
parentfeature: move cursor to position on click+alt. Closes T5537 (diff)
downloadterminology-3cafc4272d6b1600f323eb785e76a662bc7818f2.tar.gz
feature: click-alt tries to handle wrapped CLI. Closes https://phab.enlightenment.org/T5537
Diffstat (limited to 'src/bin/termptyops.c')
-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)
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"));
}