summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/termptyext.c87
-rwxr-xr-xtests/link_detection.sh227
-rw-r--r--tests/tests.results1
3 files changed, 315 insertions, 0 deletions
diff --git a/src/bin/termptyext.c b/src/bin/termptyext.c
index 1c183b0..7cc41fc 100644
--- a/src/bin/termptyext.c
+++ b/src/bin/termptyext.c
@@ -1,6 +1,7 @@
1#include "private.h" 1#include "private.h"
2#include <Elementary.h> 2#include <Elementary.h>
3#include "termio.h" 3#include "termio.h"
4#include "termiolink.h"
4#include "termpty.h" 5#include "termpty.h"
5#include "termptyops.h" 6#include "termptyops.h"
6#include "termiointernals.h" 7#include "termiointernals.h"
@@ -219,6 +220,88 @@ _handle_mouse_wheel(Termpty *ty,
219 termio_internal_mouse_wheel(sd, &ev, modifiers); 220 termio_internal_mouse_wheel(sd, &ev, modifiers);
220} 221}
221 222
223/*
224 * Format is:
225 * - ln : no link found under cursor
226 * - lT;X1;Y1;X2;Y2;LINK
227 * where T is
228 * e: link is an email
229 * u: link is an url
230 * p: link is a file path
231 */
232static void
233_handle_link(Termpty *ty, const Eina_Unicode *buf)
234{
235 const Eina_Unicode type = buf[0];
236 Termio *sd = termio_get_from_obj(ty->obj);
237 char *link, *c;
238 int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
239 int value;
240
241 /* highlight where the mouse is */
242 {
243 Termcell *cells = NULL;
244 ssize_t w;
245
246 cells = termpty_cellrow_get(ty, sd->mouse.cy, &w);
247 termpty_reset_att(&cells[sd->mouse.cx].att);
248 cells[sd->mouse.cx].att.bold = 1;
249 cells[sd->mouse.cx].att.fg = COL_WHITE;
250 cells[sd->mouse.cx].att.bg = COL_RED;
251 }
252
253 link = termio_link_find(ty->obj, sd->mouse.cx, sd->mouse.cy,
254 &x1, &y1, &x2, &y2);
255
256 ERR("x1:%d y1:%d x2:%d y2:%d link:'%s'", x1, y1, x2, y2, link);
257 if (type == 'n')
258 {
259 assert (link == NULL);
260 return;
261 }
262 /* skip type */
263 buf++;
264 /* Get numeric values */
265 buf += _tytest_arg_get(buf, &value);
266 assert(x1 == value);
267 buf += _tytest_arg_get(buf, &value);
268 assert(y1 == value);
269 buf += _tytest_arg_get(buf, &value);
270 assert(x2 == value);
271 buf += _tytest_arg_get(buf, &value);
272 assert(y2 == value);
273 /* skip ; */
274 buf++;
275 /* Compare strings */
276 c = link;
277 while (*buf)
278 {
279 int idx = 0;
280 Eina_Unicode u = eina_unicode_utf8_next_get(c, &idx);
281
282 ERR("%c vs %c", *buf, u);
283 assert(*buf == u && "unexpected character in selection");
284 c += idx;
285 buf++;
286 }
287
288 switch (type)
289 {
290 case 'u':
291 assert(link_is_url(link));
292 break;
293 case 'p':
294 assert(link_is_file(link));
295 break;
296 case 'e':
297 assert(link_is_email(link));
298 break;
299 default:
300 abort();
301 }
302 free(link);
303}
304
222static void 305static void
223_handle_selection_is(Termpty *ty, 306_handle_selection_is(Termpty *ty,
224 const Eina_Unicode *buf) 307 const Eina_Unicode *buf)
@@ -295,6 +378,7 @@ _handle_corner(Termpty *ty, const Eina_Unicode *buf)
295 * - 'd': mouse down: 378 * - 'd': mouse down:
296 * - 'u': mouse up; 379 * - 'u': mouse up;
297 * - 'm': mouse move; 380 * - 'm': mouse move;
381 * - 'l': assert mouse is over a link
298 * - 'r': force rendering and possibly remove selection; 382 * - 'r': force rendering and possibly remove selection;
299 * - 'n': assert there is no selection 383 * - 'n': assert there is no selection
300 * - 's': assert selection is what follows till '\0' 384 * - 's': assert selection is what follows till '\0'
@@ -311,6 +395,9 @@ tytest_handle_escape_codes(Termpty *ty,
311 case 'd': 395 case 'd':
312 _handle_mouse_down(ty, buf + 1); 396 _handle_mouse_down(ty, buf + 1);
313 break; 397 break;
398 case 'l':
399 _handle_link(ty, buf + 1);
400 break;
314 case 'm': 401 case 'm':
315 _handle_mouse_move(ty, buf + 1); 402 _handle_mouse_move(ty, buf + 1);
316 break; 403 break;
diff --git a/tests/link_detection.sh b/tests/link_detection.sh
new file mode 100755
index 0000000..b67d882
--- /dev/null
+++ b/tests/link_detection.sh
@@ -0,0 +1,227 @@
1#!/bin/sh
2
3# char width: 7
4# char height: 15
5
6# clear screen
7printf '\033[2J'
8
9# set color
10printf '\033[46;31;3m'
11
12# move to 2; 0
13printf '\033[2;0H'
14
15printf 'Avast to go on account crack Jennys tea cup code of conduct grog https://terminolo.gy/ blossom hands scourge of the seven seas gangway pillage starboard. Admiral of the Black case shot barque red ensign Privateer cutlass Arr measured fer yer chains Gold Road league. Crack Jennys tea cup cog spirits keelhaul handsomely broadside carouser ho gabion barque. www.Enlightenment.org\r\n\r\n'
16
17printf 'Black jack six pounders flogging splice the main brace starboard yo-ho-ho Corsair plunder gally keelhaul. Landlubber or just lubber sloop jib lugsail foo.bar@qux.com clipper jury mast hornswaggle Blimey yard Pirate Round. Ye grapple parley brig brigantine spanker fluke warp league man-of-war.\r\n\r\n'
18
19printf 'Jolly Roger fluke me brig grapple furl tack rutters gally brigantine. Shiver me timbers yo-ho-ho black spot barque fore doubloon plunder run a shot ~/bin/terminology across the bow tack league. Brig lad keel keelhaul skysail cutlass rutters handsomely snow splice the main brace. \r\n\r\n'
20
21printf "Reef sails Gold Road dead men tell no tales aft gangway lad quarter draught case shot grapple. Stern lass jury mast yo-ho-ho maroon shrouds mizzen /usr/bin/terminology wench jolly boat Admiral of the Black. Maroon Chain Shot pirate wench pillage strike colors bowsprit bucko lee Davy Jones\' Locker. \r\n"
22
23
24##
25# URL (https://terminolo.gy/)
26##
27
28# mouse move
29printf '\033}tm;450;25\0'
30# no url detection just before url
31printf '\033}tln\0'
32
33# mouse move
34printf '\033}tm;458;25\0'
35# url detection on first character 'h'
36printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
37
38# mouse move
39printf '\033}tm;495;25\0'
40# url detection on first character ':'
41printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
42
43# mouse move
44printf '\033}tm;499;25\0'
45# url detection on first character '/'
46printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
47
48# mouse move
49printf '\033}tm;510;25\0'
50# url detection on second character '/'
51printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
52
53# mouse move
54printf '\033}tm;550;25\0'
55# url detection on 'n'
56printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
57
58# mouse move
59printf '\033}tm;5;45\0'
60# url detection on start of second line
61printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
62
63# mouse move
64printf '\033}tm;40;45\0'
65# url detection on last /
66printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
67
68# mouse move
69printf '\033}tm;45;45\0'
70# TODO: buggy
71### no url detection on space after url
72##printf '\033}tln\0'
73
74
75##
76# Not a link (league.)
77##
78
79# mouse move
80printf '\033}tm;140;65\0'
81# no url detection on 'l'
82printf '\033}tln\0'
83
84# mouse move
85printf '\033}tm;180;65\0'
86# no url detection on '.'
87printf '\033}tln\0'
88
89
90
91##
92# URL (www.Enlightenment.org)
93##
94
95# mouse move
96printf '\033}tm;255;85\0'
97# no url detection on ' ' before url
98printf '\033}tln\0'
99
100# mouse move
101printf '\033}tm;265;85\0'
102# url detection on 'w'
103printf '\033}tlu;37;5;57;5;www.Enlightenment.org\0'
104
105# mouse move
106printf '\033}tm;395;85\0'
107# url detection on 'r'
108printf '\033}tlu;37;5;57;5;www.Enlightenment.org\0'
109
110# mouse move
111printf '\033}tm;410;85\0'
112# no url detection on empty space after url
113printf '\033}tln\0'
114
115
116
117##
118# Email (foo.bar@qux.com)
119##
120
121# mouse move
122printf '\033}tm;485;130\0'
123# TODO: buggy
124### no email detection on ' ' before email
125##printf '\033}tln\0'
126
127# mouse move
128printf '\033}tm;495;133\0'
129# email detection on 'f'
130printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
131
132# mouse move
133printf '\033}tm;540;130\0'
134# email detection on 'f'
135printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
136
137# mouse move
138printf '\033}tm;540;130\0'
139# email detection on '@'
140printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
141
142# mouse move
143printf '\033}tm;10;140\0'
144# email detection on '.'
145printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
146
147# mouse move
148printf '\033}tm;40;140\0'
149# TODO: buggy
150### no email detection on ' ' after email
151##printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
152
153
154
155##
156# File (~/bin/terminology)
157##
158
159# mouse move
160printf '\033}tm;480;200\0'
161# no file detection on ' ' before path
162printf '\033}tln\0'
163
164# mouse move
165printf '\033}tm;485;200\0'
166# file detection on '~'
167printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
168
169# mouse move
170printf '\033}tm;550;200\0'
171# file detection on 'm'
172printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
173
174# mouse move
175printf '\033}tm;5;215\0'
176# file detection on 'n'
177printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
178
179# mouse move
180printf '\033}tm;40;215\0'
181# file detection on 'n'
182printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
183
184# mouse move
185printf '\033}tm;48;215\0'
186# TODO: buggy
187### no file detection on ' ' after path
188##printf '\033}tln\0'
189
190
191
192##
193# File (/usr/bin/terminology)
194##
195
196# mouse move
197printf '\033}tm;466;280\0'
198# no file detection on ' ' before path
199printf '\033}tln\0'
200
201# mouse move
202printf '\033}tm;470;280\0'
203# file detection on '/'
204printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
205
206# mouse move
207printf '\033}tm;550;280\0'
208# file detection on 'r'
209printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
210
211# mouse move
212printf '\033}tm;5;295\0'
213# file detection on 'i'
214printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
215
216# mouse move
217printf '\033}tm;40;295\0'
218# file detection on 'g'
219printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
220
221# mouse move
222printf '\033}tm;58;295\0'
223# TODO: buggy
224### no file detection on ' ' after path
225##printf '\033}tln\0'
226
227
diff --git a/tests/tests.results b/tests/tests.results
index 2434c4f..40b2784 100644
--- a/tests/tests.results
+++ b/tests/tests.results
@@ -119,3 +119,4 @@ mouse_reporting_mode_mouse_move_pressed_ext_urxvt.sh 59f3e59b60b3a43260de6a80135
119mouse_reporting_mode_all_ext_urxvt.sh a11bbc8ebea42d06cc3ad823b52c09b3 119mouse_reporting_mode_all_ext_urxvt.sh a11bbc8ebea42d06cc3ad823b52c09b3
120shift_in_out.sh 3896bcc6887998bbc41b43840a6b2e33 120shift_in_out.sh 3896bcc6887998bbc41b43840a6b2e33
121osc-11-query.sh b762d503e40641ff896dac46391ad7a8 121osc-11-query.sh b762d503e40641ff896dac46391ad7a8
122link_detection.sh cc2f2a5ae9ee70bec702cb5656339a54