Enable focus reporting only for terminals that support it

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.
This commit is contained in:
stk 2023-03-11 20:08:55 +01:00 committed by Garrett D'Amore
parent 85dc29bf8a
commit 622b6c2aa7
2 changed files with 21 additions and 2 deletions

View File

@ -230,6 +230,8 @@ type Terminfo struct {
EnterUrl string
ExitUrl string
SetWindowSize string
EnableFocusReporting string
DisableFocusReporting string
}
const (

View File

@ -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
@ -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() {
@ -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) {