Skip to content

Commit

Permalink
Add support for OSC 777 (notify)
Browse files Browse the repository at this point in the history
This considers OSC 777 is supported (or at least correctly dropped)
when the terminal supports Ms (usually OSC 52).

See: gdamore#499
  • Loading branch information
delthas committed Jul 5, 2023
1 parent 3353469 commit 83fbd7b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions console_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,10 @@ func (s *cScreen) Size() (int, int) {
return w, h
}

func (s *cScreen) Notify(title string, body string) bool {
return false
}

func (s *cScreen) SetSize(w, h int) {
xy, _, _ := procGetLargestConsoleWindowSize.Call(uintptr(s.out))

Expand Down
7 changes: 7 additions & 0 deletions screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ type Screen interface {
// when unsuccessful.
Beep() error

// Notify attempts to send a desktop notification with the given notification
// title and body.
//
// Many terminals cannot support this. Most terminals also drop the notification
// if the terminal window is currently focused.
Notify(title string, body string) bool

// SetSize attempts to resize the window. It also invalidates the cells and
// calls the resize function. Note that if the window size is changed, it will
// not be restored upon application exit.
Expand Down
4 changes: 4 additions & 0 deletions simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ func (s *simscreen) CharacterSet() string {
return s.charset
}

func (s *simscreen) Notify(title string, body string) bool {
return false
}

func (s *simscreen) SetSize(w, h int) {
s.Lock()
newc := make([]SimCell, w*h)
Expand Down
18 changes: 16 additions & 2 deletions tscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ type tScreen struct {
disablePaste string
enterUrl string
exitUrl string
notification string
setWinSize string
cursorStyles map[CursorStyle]string
cursorStyle CursorStyle
Expand Down Expand Up @@ -348,8 +349,8 @@ func (t *tScreen) prepareBracketedPaste() {
func (t *tScreen) prepareExtendedOSC() {
// Linux is a special beast - because it has a mouse entry, but does
// not swallow these OSC commands properly.
if (strings.Contains(t.ti.Name, "linux")) {
return;
if strings.Contains(t.ti.Name, "linux") {
return
}
// More stuff for limits in terminfo. This time we are applying
// the most common OSC (operating system commands). Generally
Expand All @@ -368,6 +369,10 @@ func (t *tScreen) prepareExtendedOSC() {
} else if t.ti.Mouse != "" {
t.setWinSize = "\x1b[8;%p1%p2%d;%dt"
}

if t.ti.Mouse != "" {
t.notification = "\x1b]777;notify;%p1%s;%p2%s\a"
}
}

func (t *tScreen) prepareCursorStyles() {
Expand Down Expand Up @@ -1758,6 +1763,15 @@ func (t *tScreen) HasKey(k Key) bool {
return t.keyexist[k]
}

func (t *tScreen) Notify(title string, body string) bool {
if t.notification == "" {
return false
}
ti := t.ti
t.TPuts(ti.TParm(t.notification, title, body))
return true
}

func (t *tScreen) SetSize(w, h int) {
if t.setWinSize != "" {
t.TPuts(t.ti.TParm(t.setWinSize, w, h))
Expand Down

0 comments on commit 83fbd7b

Please sign in to comment.