From b3fbfa81fe98a92019a129c97b11d6ba42e9fdb5 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 28 Nov 2024 12:18:22 +0100 Subject: [PATCH] include/ttyutils: add terminal hyperlink ESC sequences Signed-off-by: Karel Zak --- include/ttyutils.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/ttyutils.h b/include/ttyutils.h index 39182b66bb..46df3cddd2 100644 --- a/include/ttyutils.h +++ b/include/ttyutils.h @@ -7,6 +7,7 @@ #ifndef UTIL_LINUX_TTYUTILS_H #define UTIL_LINUX_TTYUTILS_H +#include #include #include #include @@ -210,4 +211,30 @@ static inline void reset_virtual_console(struct termios *tp, int flags) tp->c_cc[VEOL2] = _POSIX_VDISABLE; } +#define UL_OSC8 "\033]8" /* operating system command) */ +#define UL_ST "\033\\" /* string terminator */ + +/* OSC8 hyperlink is composed from: + * + * UL_HYPERLINK_START UL_HYPERLINK_PARAMS UL_HYPERLINK_LINK UL_HYPERLINK_END + * + * Alternatively, BEL (\a) can be used instead of ST. + */ +#define UL_HYPERLINK_START UL_OSC8 +#define UL_HYPERLINK_PARAMS ";;" +#define UL_HYPERLINK_LINK UL_ST +#define UL_HYPERLINK_END (UL_OSC8 ";;" UL_ST) + +static inline void ul_fputs_hyperlink(const char *uri, const char *link, FILE *out) +{ + fputs(UL_HYPERLINK_START, out); + fputs(UL_HYPERLINK_PARAMS, out); + fputs(uri, out); + + fputs(UL_HYPERLINK_LINK, out); + fputs(link, out); + + fputs(UL_HYPERLINK_END, out); +} + #endif /* UTIL_LINUX_TTYUTILS_H */ -- 2.47.3