Skip to content

Commit

Permalink
Enable focus reporting only for terminals that support it
Browse files Browse the repository at this point in the history
We assume that any terminal that supports mouse reporting will also support
focus reporting; but we also add an entry to Terminfo to let specific terminals
override it if needed.
  • Loading branch information
stk committed Mar 11, 2023
1 parent 2f0b4dd commit 0732b36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions terminfo/terminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ type Terminfo struct {
EnterUrl string
ExitUrl string
SetWindowSize string
EnableFocusReporting string
DisableFocusReporting string
}

const (
Expand Down
21 changes: 19 additions & 2 deletions tscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ type tScreen struct {
enterUrl string
exitUrl string
setWinSize string
enableFocus string
disableFocus string
cursorStyles map[CursorStyle]string
cursorStyle CursorStyle
saved *term.State
Expand Down Expand Up @@ -366,6 +368,17 @@ func (t *tScreen) prepareExtendedOSC() {
} else if t.ti.Mouse != "" {
t.setWinSize = "\x1b[8;%p1%p2%d;%dt"
}

if t.ti.EnableFocusReporting != "" {
t.enableFocus = t.ti.EnableFocusReporting
} else if t.ti.Mouse != "" {
t.enableFocus = "\x1b[?1004h"
}
if t.ti.DisableFocusReporting != "" {
t.disableFocus = t.ti.DisableFocusReporting
} else if t.ti.Mouse != "" {
t.disableFocus = "\x1b[?1004l"
}
}

func (t *tScreen) prepareCursorStyles() {
Expand Down Expand Up @@ -1044,11 +1057,15 @@ func (t *tScreen) enablePasting(on bool) {
}

func (t *tScreen) enableFocusReporting() {
t.TPuts("\x1b[?1004h")
if t.enableFocus != "" {
t.TPuts(t.enableFocus)
}
}

func (t *tScreen) disableFocusReporting() {
t.TPuts("\x1b[?1004l")
if t.disableFocus != "" {
t.TPuts(t.disableFocus)
}
}

func (t *tScreen) Size() (int, int) {
Expand Down

0 comments on commit 0732b36

Please sign in to comment.