| 1 | package vt |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | |
| 6 | "github.com/charmbracelet/x/ansi" |
| 7 | ) |
| 8 | |
| 9 | // Focus sends the terminal a focus event if focus events mode is enabled. |
| 10 | // This is the opposite of [Blur]. |
| 11 | func (e *Emulator) Focus() { |
| 12 | e.focus(true) |
| 13 | } |
| 14 | |
| 15 | // Blur sends the terminal a blur event if focus events mode is enabled. |
| 16 | // This is the opposite of [Focus]. |
| 17 | func (e *Emulator) Blur() { |
| 18 | e.focus(false) |
| 19 | } |
| 20 | |
| 21 | func (e *Emulator) focus(focus bool) { |
| 22 | if mode, ok := e.modes[ansi.FocusEventMode]; ok && mode.IsSet() { |
| 23 | if focus { |
| 24 | _, _ = io.WriteString(e.pw, ansi.Focus) |
| 25 | } else { |
| 26 | _, _ = io.WriteString(e.pw, ansi.Blur) |
| 27 | } |
| 28 | } |
| 29 | } |