From 622b6c2aa75e77091a1471d3ad2531c0ffc000ce Mon Sep 17 00:00:00 2001 From: stk Date: Sat, 11 Mar 2023 20:08:55 +0100 Subject: [PATCH] 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. --- terminfo/terminfo.go | 2 ++ tscreen.go | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/terminfo/terminfo.go b/terminfo/terminfo.go index cf15786..c248dd4 100644 --- a/terminfo/terminfo.go +++ b/terminfo/terminfo.go @@ -230,6 +230,8 @@ type Terminfo struct { EnterUrl string ExitUrl string SetWindowSize string + EnableFocusReporting string + DisableFocusReporting string } const ( diff --git a/tscreen.go b/tscreen.go index 78f3975..63492d7 100644 --- a/tscreen.go +++ b/tscreen.go @@ -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) {