diff --git a/man/remind.1.in b/man/remind.1.in index 1fc2f1b7..d731ca99 100644 --- a/man/remind.1.in +++ b/man/remind.1.in @@ -102,6 +102,12 @@ flag also enables the use of the UNICODE "left-to-right" mark that can fix up formatting problems with right-to-left languages in the calendar display. .TP +.B 'z' +causes \fBRemind\fR to use escape sequences to turn reminders with a +"URL" info string into hyperlinks. In order to work, your terminal +must support the escape sequences documented at +https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda +.TP .B 'c' causes \fBRemind\fR to use VT100 escape sequences to approximate SPECIAL COLOR reminders. Note that this flag is kept for diff --git a/src/calendar.c b/src/calendar.c index baa0bb3b..5b8518f5 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -99,6 +99,9 @@ static struct line_drawing UTF8Drawing = { "\xe2\x94\x80" }; +static char const *start_link = "\x1B]8;;"; +static char const *end_link = "\x1B]8;;\x1B\\"; + static char *VT100Colors[2][2][2][2] /* [Br][R][G][B] */ = { { /*** DIM COLORS ***/ @@ -301,6 +304,7 @@ static void WriteTopCalLine (void); static void WriteBottomCalLine (void); static void WriteIntermediateCalLine (void); static void WriteCalDays (void); +static char const *get_url(TrigInfo *infos); static int DayOf(int dse) @@ -1557,6 +1561,10 @@ static int WriteOneColLine(int col) int clamp = 1; int numwritten = 0; int d = ColToDay[col]; + char const *url = NULL; + if (LinksInTerminal) { + url = get_url(e->infos); + } if (d && UseBGVTColors && bgcolor[d][0] != -1) { clamp = 0; } @@ -1605,6 +1613,10 @@ static int WriteOneColLine(int col) ColorizeEntry(e, clamp); } + if (LinksInTerminal && url) { + printf("%s", start_link); + printf("%s\x1B\\", url); + } /* If we couldn't find a space char, print what we have. */ if (!wspace) { for (ws = e->wc_pos; numwritten < ColSpaces; ws++) { @@ -1639,6 +1651,9 @@ static int WriteOneColLine(int col) } } + if (LinksInTerminal && url) { + printf("%s", end_link); + } /* Decolorize reminder if necessary, but keep any SHADE */ if (UseVTColors && e->is_color) { printf("%s", Decolorize()); @@ -2462,6 +2477,30 @@ void WriteJSONTimeTrigger(TimeTrig const *tt) } } +static char const * +get_url(TrigInfo *infos) +{ + TrigInfo *ti = infos; + char const *url; + while (ti) { + char const *colon = strchr(ti->info, ':'); + if (!colon) { + ti = ti->next; + continue; + } + if (!strncasecmp(ti->info, "url", colon-ti->info)) { + url = colon+1; + while (*url && isspace(*url)) { + url++; + } + if (!*url) return NULL; + return url; + } + ti = ti->next; + } + return NULL; +} + void WriteJSONInfoChain(TrigInfo *ti) { diff --git a/src/globals.h b/src/globals.h index 285aaa5f..e2bc435d 100644 --- a/src/globals.h +++ b/src/globals.h @@ -106,6 +106,7 @@ EXTERN INIT( int DefaultPrio, NO_PRIORITY); EXTERN INIT( int SysTime, -1); EXTERN INIT( int LocalSysTime, -1); EXTERN INIT( int ParseUntriggered, 0); +EXTERN INIT( int LinksInTerminal, 0); EXTERN char const *InitialFile; EXTERN char const *LocalTimeZone; diff --git a/src/init.c b/src/init.c index ca987226..6773ba5e 100644 --- a/src/init.c +++ b/src/init.c @@ -519,6 +519,11 @@ void InitRemind(int argc, char const *argv[]) arg++; continue; } + if (*arg == 'z' || *arg == 'Z') { + LinksInTerminal = 1; + arg++; + continue; + } break; } if (weeks) {