forked from enlightenment/terminology
termptyext: add tests on link detection
This commit is contained in:
parent
2c5bab7b8d
commit
02a418b290
|
@ -1,6 +1,7 @@
|
|||
#include "private.h"
|
||||
#include <Elementary.h>
|
||||
#include "termio.h"
|
||||
#include "termiolink.h"
|
||||
#include "termpty.h"
|
||||
#include "termptyops.h"
|
||||
#include "termiointernals.h"
|
||||
|
@ -219,6 +220,88 @@ _handle_mouse_wheel(Termpty *ty,
|
|||
termio_internal_mouse_wheel(sd, &ev, modifiers);
|
||||
}
|
||||
|
||||
/*
|
||||
* Format is:
|
||||
* - ln : no link found under cursor
|
||||
* - lT;X1;Y1;X2;Y2;LINK
|
||||
* where T is
|
||||
* e: link is an email
|
||||
* u: link is an url
|
||||
* p: link is a file path
|
||||
*/
|
||||
static void
|
||||
_handle_link(Termpty *ty, const Eina_Unicode *buf)
|
||||
{
|
||||
const Eina_Unicode type = buf[0];
|
||||
Termio *sd = termio_get_from_obj(ty->obj);
|
||||
char *link, *c;
|
||||
int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
|
||||
int value;
|
||||
|
||||
/* highlight where the mouse is */
|
||||
{
|
||||
Termcell *cells = NULL;
|
||||
ssize_t w;
|
||||
|
||||
cells = termpty_cellrow_get(ty, sd->mouse.cy, &w);
|
||||
termpty_reset_att(&cells[sd->mouse.cx].att);
|
||||
cells[sd->mouse.cx].att.bold = 1;
|
||||
cells[sd->mouse.cx].att.fg = COL_WHITE;
|
||||
cells[sd->mouse.cx].att.bg = COL_RED;
|
||||
}
|
||||
|
||||
link = termio_link_find(ty->obj, sd->mouse.cx, sd->mouse.cy,
|
||||
&x1, &y1, &x2, &y2);
|
||||
|
||||
ERR("x1:%d y1:%d x2:%d y2:%d link:'%s'", x1, y1, x2, y2, link);
|
||||
if (type == 'n')
|
||||
{
|
||||
assert (link == NULL);
|
||||
return;
|
||||
}
|
||||
/* skip type */
|
||||
buf++;
|
||||
/* Get numeric values */
|
||||
buf += _tytest_arg_get(buf, &value);
|
||||
assert(x1 == value);
|
||||
buf += _tytest_arg_get(buf, &value);
|
||||
assert(y1 == value);
|
||||
buf += _tytest_arg_get(buf, &value);
|
||||
assert(x2 == value);
|
||||
buf += _tytest_arg_get(buf, &value);
|
||||
assert(y2 == value);
|
||||
/* skip ; */
|
||||
buf++;
|
||||
/* Compare strings */
|
||||
c = link;
|
||||
while (*buf)
|
||||
{
|
||||
int idx = 0;
|
||||
Eina_Unicode u = eina_unicode_utf8_next_get(c, &idx);
|
||||
|
||||
ERR("%c vs %c", *buf, u);
|
||||
assert(*buf == u && "unexpected character in selection");
|
||||
c += idx;
|
||||
buf++;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 'u':
|
||||
assert(link_is_url(link));
|
||||
break;
|
||||
case 'p':
|
||||
assert(link_is_file(link));
|
||||
break;
|
||||
case 'e':
|
||||
assert(link_is_email(link));
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
free(link);
|
||||
}
|
||||
|
||||
static void
|
||||
_handle_selection_is(Termpty *ty,
|
||||
const Eina_Unicode *buf)
|
||||
|
@ -295,6 +378,7 @@ _handle_corner(Termpty *ty, const Eina_Unicode *buf)
|
|||
* - 'd': mouse down:
|
||||
* - 'u': mouse up;
|
||||
* - 'm': mouse move;
|
||||
* - 'l': assert mouse is over a link
|
||||
* - 'r': force rendering and possibly remove selection;
|
||||
* - 'n': assert there is no selection
|
||||
* - 's': assert selection is what follows till '\0'
|
||||
|
@ -311,6 +395,9 @@ tytest_handle_escape_codes(Termpty *ty,
|
|||
case 'd':
|
||||
_handle_mouse_down(ty, buf + 1);
|
||||
break;
|
||||
case 'l':
|
||||
_handle_link(ty, buf + 1);
|
||||
break;
|
||||
case 'm':
|
||||
_handle_mouse_move(ty, buf + 1);
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
#!/bin/sh
|
||||
|
||||
# char width: 7
|
||||
# char height: 15
|
||||
|
||||
# clear screen
|
||||
printf '\033[2J'
|
||||
|
||||
# set color
|
||||
printf '\033[46;31;3m'
|
||||
|
||||
# move to 2; 0
|
||||
printf '\033[2;0H'
|
||||
|
||||
printf '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'
|
||||
|
||||
printf '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'
|
||||
|
||||
printf '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'
|
||||
|
||||
printf "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"
|
||||
|
||||
|
||||
##
|
||||
# URL (https://terminolo.gy/)
|
||||
##
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;450;25\0'
|
||||
# no url detection just before url
|
||||
printf '\033}tln\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;458;25\0'
|
||||
# url detection on first character 'h'
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;495;25\0'
|
||||
# url detection on first character ':'
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;499;25\0'
|
||||
# url detection on first character '/'
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;510;25\0'
|
||||
# url detection on second character '/'
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;550;25\0'
|
||||
# url detection on 'n'
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;5;45\0'
|
||||
# url detection on start of second line
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;40;45\0'
|
||||
# url detection on last /
|
||||
printf '\033}tlu;65;1;5;2;https://terminolo.gy/\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;45;45\0'
|
||||
# TODO: buggy
|
||||
### no url detection on space after url
|
||||
##printf '\033}tln\0'
|
||||
|
||||
|
||||
##
|
||||
# Not a link (league.)
|
||||
##
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;140;65\0'
|
||||
# no url detection on 'l'
|
||||
printf '\033}tln\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;180;65\0'
|
||||
# no url detection on '.'
|
||||
printf '\033}tln\0'
|
||||
|
||||
|
||||
|
||||
##
|
||||
# URL (www.Enlightenment.org)
|
||||
##
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;255;85\0'
|
||||
# no url detection on ' ' before url
|
||||
printf '\033}tln\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;265;85\0'
|
||||
# url detection on 'w'
|
||||
printf '\033}tlu;37;5;57;5;www.Enlightenment.org\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;395;85\0'
|
||||
# url detection on 'r'
|
||||
printf '\033}tlu;37;5;57;5;www.Enlightenment.org\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;410;85\0'
|
||||
# no url detection on empty space after url
|
||||
printf '\033}tln\0'
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Email (foo.bar@qux.com)
|
||||
##
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;485;130\0'
|
||||
# TODO: buggy
|
||||
### no email detection on ' ' before email
|
||||
##printf '\033}tln\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;495;133\0'
|
||||
# email detection on 'f'
|
||||
printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;540;130\0'
|
||||
# email detection on 'f'
|
||||
printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;540;130\0'
|
||||
# email detection on '@'
|
||||
printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;10;140\0'
|
||||
# email detection on '.'
|
||||
printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;40;140\0'
|
||||
# TODO: buggy
|
||||
### no email detection on ' ' after email
|
||||
##printf '\033}tle;70;8;4;9;foo.bar@qux.com\0'
|
||||
|
||||
|
||||
|
||||
##
|
||||
# File (~/bin/terminology)
|
||||
##
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;480;200\0'
|
||||
# no file detection on ' ' before path
|
||||
printf '\033}tln\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;485;200\0'
|
||||
# file detection on '~'
|
||||
printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;550;200\0'
|
||||
# file detection on 'm'
|
||||
printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;5;215\0'
|
||||
# file detection on 'n'
|
||||
printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;40;215\0'
|
||||
# file detection on 'n'
|
||||
printf '\033}tlp;69;13;5;14;%s/bin/terminology\0' "$HOME"
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;48;215\0'
|
||||
# TODO: buggy
|
||||
### no file detection on ' ' after path
|
||||
##printf '\033}tln\0'
|
||||
|
||||
|
||||
|
||||
##
|
||||
# File (/usr/bin/terminology)
|
||||
##
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;466;280\0'
|
||||
# no file detection on ' ' before path
|
||||
printf '\033}tln\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;470;280\0'
|
||||
# file detection on '/'
|
||||
printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;550;280\0'
|
||||
# file detection on 'r'
|
||||
printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;5;295\0'
|
||||
# file detection on 'i'
|
||||
printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;40;295\0'
|
||||
# file detection on 'g'
|
||||
printf '\033}tlp;67;18;6;19;/usr/bin/terminology\0'
|
||||
|
||||
# mouse move
|
||||
printf '\033}tm;58;295\0'
|
||||
# TODO: buggy
|
||||
### no file detection on ' ' after path
|
||||
##printf '\033}tln\0'
|
||||
|
||||
|
|
@ -119,3 +119,4 @@ mouse_reporting_mode_mouse_move_pressed_ext_urxvt.sh 59f3e59b60b3a43260de6a80135
|
|||
mouse_reporting_mode_all_ext_urxvt.sh a11bbc8ebea42d06cc3ad823b52c09b3
|
||||
shift_in_out.sh 3896bcc6887998bbc41b43840a6b2e33
|
||||
osc-11-query.sh b762d503e40641ff896dac46391ad7a8
|
||||
link_detection.sh cc2f2a5ae9ee70bec702cb5656339a54
|
||||
|
|
Loading…
Reference in New Issue