uncurses/ansi/focus.rs
1//! Focus-event report sequences.
2//!
3//! ## Category
4//!
5//! When focus tracking is enabled, terminals send CSI `I` on focus gain and CSI
6//! `O` on focus loss. The constants expose those inbound byte sequences, and the
7//! writers can replay them in tests or recordings.
8//!
9//! ## CSI conventions
10//!
11//! Both reports use the 7-bit CSI introducer with no parameters: `ESC [ I` and
12//! `ESC [ O`.
13//!
14//! ## Mode interaction
15//!
16//! Focus reports are controlled by [`Mode::FOCUS`](crate::ansi::mode::Mode::FOCUS)
17//! (DEC private mode 1004). Applications enable the mode with
18//! [`crate::ansi::mode::write_set_mode`] and then parse these reports from input.
19
20use std::io::{self, Write};
21
22/// Focus-gained report: exact bytes `ESC [ I` (`b"\x1b[I"`).
23///
24/// Terminals send this after focus tracking mode is enabled.
25pub const FOCUS: &[u8] = b"\x1b[I";
26
27/// Focus-lost report: exact bytes `ESC [ O` (`b"\x1b[O"`).
28///
29/// Terminals send this after focus tracking mode is enabled.
30pub const BLUR: &[u8] = b"\x1b[O";
31
32/// Write the focus-gained report bytes `ESC [ I`.
33///
34/// Useful for tests or replay; applications normally receive this from the terminal.
35pub fn write_focus<W: Write>(w: &mut W) -> io::Result<()> {
36 w.write_all(FOCUS)
37}
38
39/// Write the focus-lost report bytes `ESC [ O`.
40///
41/// Useful for tests or replay; applications normally receive this from the terminal.
42pub fn write_blur<W: Write>(w: &mut W) -> io::Result<()> {
43 w.write_all(BLUR)
44}