From 3f7674a2e99f98eb8c1addfb4037e191d9381641 Mon Sep 17 00:00:00 2001
From: Stefan Haller <stefan@haller-berlin.de>
Date: Fri, 16 Aug 2024 11:25:28 +0200
Subject: [PATCH] Add function to render a hyperlink

It might seem cleaner to integrate this into the text style system, so that you
could say `ts := ts.Url("some link")` and then `ts.Sprint("my text")`. However,
this would require adding a new field to TextStyle, which I didn't want to do.
---
 pkg/gui/style/hyperlink.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 pkg/gui/style/hyperlink.go

diff --git a/pkg/gui/style/hyperlink.go b/pkg/gui/style/hyperlink.go
new file mode 100644
index 000000000..0585e89a9
--- /dev/null
+++ b/pkg/gui/style/hyperlink.go
@@ -0,0 +1,13 @@
+package style
+
+import "fmt"
+
+// Render the given text as an OSC 8 hyperlink
+func PrintHyperlink(text string, link string) string {
+	return fmt.Sprintf("\033]8;;%s\033\\%s\033]8;;\033\\", link, text)
+}
+
+// Render a link where the text is the same as a link
+func PrintSimpleHyperlink(link string) string {
+	return fmt.Sprintf("\033]8;;%s\033\\%s\033]8;;\033\\", link, link)
+}