Make focus reporting an opt-in feature, like mouse reporting

This commit is contained in:
stk 2023-03-12 09:49:34 +01:00 committed by Garrett D'Amore
parent 622b6c2aa7
commit f028121cb8
4 changed files with 31 additions and 1 deletions

View File

@ -129,6 +129,7 @@ func main() {
s.SetStyle(defStyle)
s.EnableMouse()
s.EnablePaste()
s.EnableFocus()
s.Clear()
posfmt := "Mouse: %d, %d "

View File

@ -139,6 +139,12 @@ type Screen interface {
// DisablePaste disables bracketed paste mode.
DisablePaste()
// EnableFocus enables reporting of focus events, if your terminal supports it.
EnableFocus()
// DisableFocus disables reporting of focus events.
DisableFocus()
// HasMouse returns true if the terminal (apparently) supports a
// mouse. Note that the return value of true doesn't guarantee that
// a mouse/pointing device is present; a false return definitely

View File

@ -325,6 +325,12 @@ func (s *simscreen) DisablePaste() {
s.paste = false
}
func (s *simscreen) EnableFocus() {
}
func (s *simscreen) DisableFocus() {
}
func (s *simscreen) Size() (int, int) {
s.Lock()
w, h := s.back.Size()

View File

@ -163,6 +163,7 @@ type tScreen struct {
wg sync.WaitGroup
mouseFlags MouseFlags
pasteEnabled bool
focusEnabled bool
sync.Mutex
}
@ -1056,6 +1057,20 @@ func (t *tScreen) enablePasting(on bool) {
}
}
func (t *tScreen) EnableFocus() {
t.Lock()
t.focusEnabled = true
t.enableFocusReporting()
t.Unlock()
}
func (t *tScreen) DisableFocus() {
t.Lock()
t.focusEnabled = false
t.disableFocusReporting()
t.Unlock()
}
func (t *tScreen) enableFocusReporting() {
if t.enableFocus != "" {
t.TPuts(t.enableFocus)
@ -1866,7 +1881,9 @@ func (t *tScreen) engage() error {
t.stopQ = stopQ
t.enableMouse(t.mouseFlags)
t.enablePasting(t.pasteEnabled)
t.enableFocusReporting()
if t.focusEnabled {
t.enableFocusReporting()
}
ti := t.ti
t.TPuts(ti.EnterCA)