File: focus.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20251028.0cf22f8%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,940 kB
  • sloc: sh: 124; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package vt

import (
	"io"

	"github.com/charmbracelet/x/ansi"
)

// Focus sends the terminal a focus event if focus events mode is enabled.
// This is the opposite of [Blur].
func (e *Emulator) Focus() {
	e.focus(true)
}

// Blur sends the terminal a blur event if focus events mode is enabled.
// This is the opposite of [Focus].
func (e *Emulator) Blur() {
	e.focus(false)
}

func (e *Emulator) focus(focus bool) {
	if mode, ok := e.modes[ansi.FocusEventMode]; ok && mode.IsSet() {
		if focus {
			_, _ = io.WriteString(e.pw, ansi.Focus)
		} else {
			_, _ = io.WriteString(e.pw, ansi.Blur)
		}
	}
}