Debian Codegraph @

Xtermina/src/escape.rs

raw symbols SCIP
1 //! Typed ANSI escape-sequence helpers.
2 //!
3 //! Termina models Control Sequence Introducer (CSI), Device Control String (DCS), and Operating
4 //! System Command (OSC) sequences it knows how to emit so callers can compose terminal control
5 //! payloads through [`Display`] instead of hand-written byte strings.
6 //!
7 //! # Examples
8 //!
9 //! ```
10 //! use termina::{
11 //! escape::{
12 //! csi::{Csi, Cursor},
13 //! CSI,
14 //! },
15 //! OneBased,
16 //! };
17 //!
18 //! let cursor_home = Csi::Cursor(Cursor::Position {
19 //! line: OneBased::new(1).unwrap(),
20 //! col: OneBased::new(1).unwrap(),
21 //! });
22 //!
23 //! assert_eq!(cursor_home.to_string(), format!("{CSI}1;1H"));
24 //! ```
25 //!
26 //! # Implementation Notes
27 //!
28 //! This module tree is adapted from [termwiz escape helpers]. It was originally yanked from TermWiz
29 //! equivalents and then trimmed into the set of escape sequences Termina needs. Most differences
30 //! are stylistic edits plus additions and subtractions in the modeled sequence set.
31 //!
32 //! [termwiz escape helpers]: https://docs.rs/termwiz/latest/termwiz/escape/index.html
33 //! [`Display`]: std::fmt::Display
34
35 pub mod csi;
36 pub mod dcs;
37 pub mod osc;
38
39 /// Control Sequence Introducer (`ESC [`), the prefix for parameterized terminal control functions.
40 ///
41 /// CSI sequences carry numeric parameters and a final byte. Termina models the supported CSI
42 /// families in [`csi::Csi`].
43 pub const CSI: &str = "\x1b[";
44
45 /// Operating System Command introducer (`ESC ]`), used for terminal integration commands.
46 ///
47 /// OSC sequences are commonly used for window titles, clipboard integration, and color queries.
48 /// Termina models the supported commands in [`osc::Osc`].
49 pub const OSC: &str = "\x1b]";
50
51 /// String Terminator (`ESC \`), used to end OSC and DCS string controls.
52 ///
53 /// Most modern terminal string controls may also be terminated by [`BEL`], but Termina emits the
54 /// explicit string terminator form for the sequences it formats.
55 pub const ST: &str = "\x1b\\";
56
57 /// Single Shift 3 (`ESC O`), the prefix used by SS3 key sequences.
58 ///
59 /// Application-keypad and function-key encodings commonly use this prefix instead of [`CSI`].
60 pub const SS3: &str = "\x1bO";
61
62 /// Device Control String introducer (`ESC P`), used for structured terminal queries.
63 ///
64 /// Termina models the supported request and response forms in [`dcs::Dcs`].
65 pub const DCS: &str = "\x1bP";
66
67 /// Bell control character (`BEL`, `0x07`).
68 ///
69 /// BEL can ring the terminal bell and is also accepted by many terminals as an OSC terminator.
70 pub const BEL: &str = "\x07";