aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--filters/colorize.c26
-rw-r--r--filters/vectors/colorize-patch.expected4
-rw-r--r--filters/vectors/colorize-quotes.expected4
4 files changed, 28 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4081aa86..e2d7ba47 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
`signature-file` and `signature-cmd` if not already present.
- All `aerc(1)` commands now interpret `aerc-templates(7)` markup.
- running commands (like mailto: or mbox:) no longer prints a success message
+- The built-in `colorize` filter now emits OSC 8 to mark URLs and emails.
### Deprecated
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