Commit 1425714e293fea96fdb04354aa47d3527030f708

Parents: 08fbbf9f1ae2bf5f948b05241d6f3ab8240c0f32

From: Moritz Poldrack <git@moritz.sh>
Date: Thu Apr 7 11:14:33 2022 +0700

added Notification ANSI-Code

		

Stats

codetable.go +3/-0
notifications.go +11/-0
notifications_test.go +10/-0

Changeset

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
diff --git a/codetable.go b/codetable.go
index 7da717e930c9b694e80b8c0a6911d64d2a04f0b4..301ad79b84648b134678a5178ed6f2360c7280c1 100644
--- a/codetable.go
+++ b/codetable.go
@@ -76,4 +76,7 @@ 	escapeTC = "\x1be["
 
 	// hyperlink
 	hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
+
+	// notification
+	notification = "\x1b]777;notify;%s;%s\a"
 )
diff --git a/notifications.go b/notifications.go
new file mode 100644
index 0000000000000000000000000000000000000000..5304ded7cf8ff6d1019bfa4aeab3e5c7407506be
--- /dev/null
+++ b/notifications.go
@@ -0,0 +1,11 @@
+package ansi
+
+import (
+	"fmt"
+)
+
+// Link creates a terminal Hyperlink that can be clicked, if the terminal
+// emulator supports it.
+func SendNotification(title, body string) string {
+	return fmt.Sprintf(notification, title, body)
+}
diff --git a/notifications_test.go b/notifications_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..42f1469ad63f67db9a43541e6d5818716442330e
--- /dev/null
+++ b/notifications_test.go
@@ -0,0 +1,10 @@
+package ansi
+
+import (
+	"fmt"
+	"testing"
+)
+
+func TestNotification(t *testing.T) {
+	fmt.Printf("Here should be no text, if your terminal supports notifications: %s\n", SendNotification("Hello from go-ansi", "This notification should be sent through your terminal emulator, it it's supported."))
+}