Skip to content

Commit

Permalink
feat: add OSC-777 support for system notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Nov 1, 2022
1 parent 42ca574 commit 973f723
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
41 changes: 22 additions & 19 deletions README.md
Expand Up @@ -248,6 +248,9 @@ output.HideCursor()

// Show the cursor
output.ShowCursor()

// Trigger notification
output.Notification("Title", "Body")
```

## Mouse
Expand Down Expand Up @@ -296,25 +299,25 @@ termenv.DisableBracketedPaste()

## Optional Feature Support

| Terminal | Alt Screen | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting | Copy (OSC52) | Hyperlinks (OSC8) | Bracketed Paste |
| ---------------- | :--------: | :----------------: | :-------------------: | :--------------: | :-----------------: | :-------------------------------: | :-------------------------------: | :----------: | :---------------: | :-------------: |
| alacritty |||||||||[^alacritty] ||
| foot |||||||||||
| kitty |||||||||||
| Konsole ||||||||[^konsole] |||
| rxvt |||||||||||
| urxvt ||||||||[^urxvt] |||
| screen ||[^mux] |||||||[^screen] ||
| st |||||||||||
| tmux ||[^mux] |||||||[^tmux] ||
| vte-based[^vte] ||||||||[^vte] |||
| wezterm |||||||||||
| xterm |||||||||||
| Linux Console |||||||||||
| Apple Terminal ||||||||[^apple] |||
| iTerm |||||||||||
| Windows cmd |||||||||||
| Windows Terminal |||||||||||
| Terminal | Alt Screen | Query Color Scheme | Query Cursor Position | Set Window Title | Change Cursor Color | Change Default Foreground Setting | Change Default Background Setting | Copy (OSC52) | Hyperlinks (OSC8) | Notifications (OSC777) | Bracketed Paste |
| ---------------- | :--------: | :----------------: | :-------------------: | :--------------: | :-----------------: | :-------------------------------: | :-------------------------------: | :----------: | :---------------: | :--------------------: | :-------------: |
| alacritty |||||||||[^alacritty] | | |
| foot |||||||||| | |
| kitty |||||||||| | |
| Konsole ||||||||[^konsole] || | |
| rxvt |||||||||| | |
| urxvt ||||||||[^urxvt] || | |
| screen ||[^mux] |||||||[^screen] | | |
| st |||||||||| | |
| tmux ||[^mux] |||||||[^tmux] | | |
| vte-based[^vte] ||||||||[^vte] || | |
| wezterm |||||||||| | |
| xterm |||||||||| | |
| Linux Console |||||||||| | |
| Apple Terminal ||||||||[^apple] || | |
| iTerm |||||||||| | |
| Windows cmd |||||||||| | |
| Windows Terminal |||||||||| | |

[^vte]: This covers all vte-based terminals, including Gnome Terminal, guake, Pantheon Terminal, Terminator, Tilix, XFCE Terminal. OSC52 is not supported, see [issue#2495](https://gitlab.gnome.org/GNOME/vte/-/issues/2495).
[^mux]: Unavailable as multiplexers (like tmux or screen) can be connected to multiple terminals (with different color settings) at the same time.
Expand Down
4 changes: 4 additions & 0 deletions examples/hello-world/main.go
Expand Up @@ -53,6 +53,10 @@ func main() {
fmt.Printf("\t%q copied to clipboard\n", hw)
fmt.Println()

termenv.Notification("Termenv", hw)
fmt.Print("\tTriggered a notification")
fmt.Println()

fmt.Printf("\t%s", termenv.Hyperlink("http://example.com", "This is a link"))
fmt.Println()
}
13 changes: 13 additions & 0 deletions notification.go
@@ -0,0 +1,13 @@
package termenv

import "fmt"

// Notification triggers a notification using OSC777.
func Notification(title, body string) {
output.Notification(title, body)
}

// Notification triggers a notification using OSC777.
func (o *Output) Notification(title, body string) {
o.WriteString(fmt.Sprintf(OSC+"777;notify;%s;%s\x1b\\", title, body))
}

0 comments on commit 973f723

Please sign in to comment.