summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2018-09-29 17:21:27 +0200
committerBoris Faure <billiob@gmail.com>2018-09-29 17:21:27 +0200
commitfccc11408247caa9728c2967fe64eab075567005 (patch)
tree893069078e2ebdb7e2e0f069cfcebf4d7da4a3ee
parent9fc660ccb2e8671fb6610f31e718496472f498cb (diff)
selection: handle scrolling and left/right margins
-rw-r--r--src/bin/termio.c124
-rwxr-xr-xtools/scroll.sh20
2 files changed, 108 insertions, 36 deletions
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 22e26ce..8593227 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -127,14 +127,101 @@ static Eina_Bool _mouse_in_selection(Termio *sd, int cx, int cy);
127 127
128/* {{{ Helpers */ 128/* {{{ Helpers */
129 129
130static void
131_termio_scroll_selection(Termio *sd, Termpty *ty,
132 int direction, int start_y, int end_y)
133{
134 if (!ty->selection.is_active)
135 return;
136
137 int sel_start_x = ty->selection.start.x;
138 int sel_start_y = ty->selection.start.y;
139 int sel_end_x = ty->selection.end.x;
140 int sel_end_y = ty->selection.end.y;
141
142 int left_margin = ty->termstate.left_margin;
143 int right_margin = ty->termstate.right_margin;
144
145 if (!ty->selection.is_top_to_bottom)
146 {
147 INT_SWAP(sel_start_y, sel_end_y);
148 INT_SWAP(sel_start_x, sel_end_x);
149 }
150
151 if (start_y <= sel_start_y &&
152 sel_end_y <= end_y)
153 {
154 if (ty->termstate.left_margin)
155 {
156 if ((ty->selection.is_box) || (sel_start_y == sel_end_y))
157 {
158 /* if selection outside scrolling area */
159 if ((sel_end_x <= left_margin) ||
160 (sel_start_x >= right_margin))
161 {
162 return;
163 }
164 /* if selection not within scrolling area */
165 if (!((sel_start_x >= left_margin) &&
166 (sel_end_x <= right_margin)))
167 {
168 _sel_set(sd, EINA_FALSE);
169 return;
170 }
171 }
172 else
173 {
174 _sel_set(sd, EINA_FALSE);
175 return;
176 }
177 }
178
179 ty->selection.orig.y += direction;
180 ty->selection.start.y += direction;
181 ty->selection.end.y += direction;
182 sel_start_y += direction;
183 sel_end_y += direction;
184 if (!(start_y <= sel_start_y &&
185 sel_end_y <= end_y))
186 {
187 _sel_set(sd, EINA_FALSE);
188 }
189 }
190 else if (!((start_y > sel_end_y) ||
191 (end_y < sel_start_y)))
192 {
193 if (ty->termstate.left_margin)
194 {
195 if ((ty->selection.is_box) || (sel_start_y == sel_end_y))
196 {
197 /* if selection outside scrolling area */
198 if ((sel_end_x <= left_margin) ||
199 (sel_start_x >= right_margin))
200 {
201 return;
202 }
203 }
204 }
205 _sel_set(sd, EINA_FALSE);
206 }
207 else if (sd->scroll > 0)
208 {
209 ty->selection.orig.y += direction;
210 ty->selection.start.y += direction;
211 ty->selection.end.y += direction;
212 }
213}
214
130void 215void
131termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y) 216termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y)
132{ 217{
133 Termpty *ty;
134 Termio *sd = evas_object_smart_data_get(obj); 218 Termio *sd = evas_object_smart_data_get(obj);
219 Termpty *ty;
135 220
136 EINA_SAFETY_ON_NULL_RETURN(sd); 221 EINA_SAFETY_ON_NULL_RETURN(sd);
137 222
223 ty = sd->pty;
224
138 if ((!sd->jump_on_change) && // if NOT scroll to bottom on updates 225 if ((!sd->jump_on_change) && // if NOT scroll to bottom on updates
139 (sd->scroll > 0)) 226 (sd->scroll > 0))
140 { 227 {
@@ -143,42 +230,9 @@ termio_scroll(Evas_Object *obj, int direction, int start_y, int end_y)
143 // adjust scroll position for added scrollback 230 // adjust scroll position for added scrollback
144 sd->scroll -= direction; 231 sd->scroll -= direction;
145 } 232 }
146 ty = sd->pty;
147 if (ty->selection.is_active)
148 {
149 int sel_start_y, sel_end_y;
150 233
151 sel_start_y = ty->selection.start.y; 234 _termio_scroll_selection(sd, ty, direction, start_y, end_y);
152 sel_end_y = ty->selection.end.y;
153 235
154 if (!ty->selection.is_top_to_bottom)
155 INT_SWAP(sel_start_y, sel_end_y);
156 if (start_y <= sel_start_y &&
157 sel_end_y <= end_y)
158 {
159 ty->selection.orig.y += direction;
160 ty->selection.start.y += direction;
161 ty->selection.end.y += direction;
162 sel_start_y += direction;
163 sel_end_y += direction;
164 if (!(start_y <= sel_start_y &&
165 sel_end_y <= end_y))
166 {
167 _sel_set(sd, EINA_FALSE);
168 }
169 }
170 else if (!((start_y > sel_end_y) ||
171 (end_y < sel_start_y)))
172 {
173 _sel_set(sd, EINA_FALSE);
174 }
175 else if (sd->scroll > 0)
176 {
177 ty->selection.orig.y += direction;
178 ty->selection.start.y += direction;
179 ty->selection.end.y += direction;
180 }
181 }
182 if (sd->link.string) 236 if (sd->link.string)
183 { 237 {
184 if (sd->link.y1 <= end_y && sd->link.y2 >= start_y) 238 if (sd->link.y1 <= end_y && sd->link.y2 >= start_y)
diff --git a/tools/scroll.sh b/tools/scroll.sh
index 39b064c..1211198 100755
--- a/tools/scroll.sh
+++ b/tools/scroll.sh
@@ -1,8 +1,26 @@
1#/bin/bash 1#/bin/bash
2 2
3# fill space with E
4printf '\033#8'
5# cursor to 0,0
6printf '\033[H'
7# restrict cursor
8printf '\033[?6h'
9# set top/bottom margins:
10printf '\033[10;20r'
11# allow left/right margins
12printf '\033[?69h'
13# set left/right margins:
14printf '\033[5;15s'
15# move to 0,0 with margins:
16printf '\033[H'
17# clean up rect
18printf '\033[1;1;11;11$z'
19echo '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
20
3I=0 21I=0
4while [ 1 ]; do 22while [ 1 ]; do
5 sleep 1 23 sleep 2
6 echo $I 24 echo $I
7 I=`expr $I + 1` 25 I=`expr $I + 1`
8done 26done