aboutsummaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2023-03-18 22:25:05 +0300
committerRobin Jarry <robin@jarry.cc>2023-03-26 21:05:46 +0200
commit65b1524bc63ddb926c4b83b1a34b89599fd8d156 (patch)
treeddec14cd5eefa9c3653ae8f8e0adf7e265d24bc3 /filters
parent946c74daeedcf9bef9972a5418044c413334b7b7 (diff)
downloadaerc-65b1524bc63ddb926c4b83b1a34b89599fd8d156.tar.gz
colorize: emit OSC 8 for URLs and emails
Mark URLs with OSC 8 escape sequence to help terminal emulators with opening multi-line URLs with the mouse and attach the hyperlink to email addresses, so the users could open them. Link: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda Signed-off-by: Kirill Chibisov <contact@kchibisov.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'filters')
-rw-r--r--filters/colorize.c26
-rw-r--r--filters/vectors/colorize-patch.expected4
-rw-r--r--filters/vectors/colorize-quotes.expected4
3 files changed, 27 insertions, 7 deletions
diff --git a/filters/colorize.c b/filters/colorize.c
index e1d57be6..26c25a8a 100644
--- a/filters/colorize.c
+++ b/filters/colorize.c
@@ -413,6 +413,17 @@ static inline size_t print_notabs(const char *in, size_t max_len)
return len;
}
+static void print_osc8(const char *url, size_t len, size_t id, bool email) {
+ printf("\x1b]8;id=colorize-%lu;", id);
+ if (url != NULL) {
+ if (email) {
+ print("mailto://");
+ }
+ print_notabs(url, len);
+ }
+ print("\x1b\\");
+}
+
static void diff_chunk(const char *in)
{
size_t len = 0;
@@ -429,17 +440,22 @@ static void diff_chunk(const char *in)
}
#define URL_RE \
- "[a-z]{2,8}://[][:alnum:]._~:/?#[@!$&'()*+,;=%-]{4,}" \
+ "([a-z]{2,8}:)//[][:alnum:]._~:/?#[@!$&'()*+,;=%-]{4,}" \
"|(mailto:)?[[:alnum:]_+.~/-]*[[:alnum:]]@[a-z][[:alnum:].-]*[a-z]"
static regex_t url_re;
static void urls(const char *in, struct style *ctx)
{
- regmatch_t groups[2];
+ /* ID of the next link to print for OSC 8. The purpose of passing
+ * explicit ID is to help terminal emulator with grouping of
+ * multi-line links in nested terminal sessions */
+ static size_t url_id = 0;
+
+ regmatch_t groups[3];
size_t len;
bool trim;
- while (!regexec(&url_re, in, 2, groups, 0)) {
+ while (!regexec(&url_re, in, 3, groups, 0)) {
in += print_notabs(in, groups[0].rm_so);
print(seq(&styles.url));
len = groups[0].rm_eo - groups[0].rm_so;
@@ -457,7 +473,11 @@ static void urls(const char *in, struct style *ctx)
break;
}
}
+ bool email = groups[2].rm_so == -1 && groups[1].rm_so == -1;
+ print_osc8(in, len, url_id, email);
in += print_notabs(in, len);
+ print_osc8(NULL, 0, url_id, email);
+ url_id++;
print(RESET);
if (ctx) {
print(seq(ctx));
diff --git a/filters/vectors/colorize-patch.expected b/filters/vectors/colorize-patch.expected
index de3f2399..619e118f 100644
--- a/filters/vectors/colorize-patch.expected
+++ b/filters/vectors/colorize-patch.expected
@@ -1,11 +1,11 @@
-From: Robin Jarry <robin@jarry.cc>
+From: Robin Jarry <]8;id=colorize-0;mailto://robin@jarry.cc\robin@jarry.cc]8;id=colorize-0;\>
Date: Mon, 26 Dec 2022 17:02:14 +0100
Subject: [PATCH aerc] doc: fix numbered lists
According to scdoc(5), numbered lists start with a period.
Fixes: af63bd0188d1 ("doc: homogenize scdoc markup")
-Signed-off-by: Robin Jarry <robin@jarry.cc>
+Signed-off-by: Robin Jarry <]8;id=colorize-1;mailto://robin@jarry.cc\robin@jarry.cc]8;id=colorize-1;\>
---
doc/aerc-stylesets.7.scd | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/filters/vectors/colorize-quotes.expected b/filters/vectors/colorize-quotes.expected
index 6e71d60a..46d3adba 100644
--- a/filters/vectors/colorize-quotes.expected
+++ b/filters/vectors/colorize-quotes.expected
@@ -17,7 +17,7 @@ nibh petentium at! Sit docendi laboramus ei, animal insolens ad mea.
> Erat alienum interpretaris has et, te vim aliquam molestie. Nam vivendum
> facilisis qualisque at, ex his mucius qualisque! Fabulas lucilius adversarium
> eu his. Cu soluta inermis accusata usu, his nulla dolore ne, vis id semper
-> detracto sententia <https://foobar.com> && "https://foobaz.org/".
+> detracto sententia <]8;id=colorize-0;https://foobar.com\https://foobar.com]8;id=colorize-0;\> && "]8;id=colorize-1;https://foobaz.org/\https://foobaz.org/]8;id=colorize-1;\".
>
> Error libris deleniti ea mei, vis at elit probo munere, his sint unum
> albucius ex.
@@ -52,7 +52,7 @@ Has putent verterem constituto ex, tale electram duo at! Ei nulla lucilius
intellegat nam, pro quod epicuri dissentiet ut, omnis voluptatibus definitiones
vim at.
-https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==
+]8;id=colorize-2;https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==\https://git-man-page-generator.lokaltog.net/#Y2xhcCQkY29tbWFuZA==]8;id=colorize-2;\
Eam mundi libris debitis ad, eam regione numquam at. Eum omnes bonorum eu,
oporteat assueverit disputationi nam ne, nonumes iracundia mea ad! Duo libris