ailloli_ui_terminal_core/mode.rs
1//! DEC/ANSI terminal input and rendering mode flags.
2
3use serde::{Deserialize, Serialize};
4
5/// Native mouse reporting mode requested by the terminal application.
6///
7/// # Examples
8///
9/// ```
10/// use ailloli_ui_terminal_core::TerminalMouseTrackingMode;
11/// assert_eq!(TerminalMouseTrackingMode::default(), TerminalMouseTrackingMode::Off);
12/// ```
13#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
14pub enum TerminalMouseTrackingMode {
15 /// Do not encode pointer events for the terminal application.
16 #[default]
17 Off,
18 /// X10 press-only reporting (DECSET 9).
19 X10,
20 /// Button press/release reporting (DECSET 1000).
21 Normal,
22 /// Report motion while a button is held (DECSET 1002).
23 ButtonMotion,
24 /// Report all pointer motion (DECSET 1003).
25 AnyMotion,
26}
27
28/// Mutable terminal mode snapshot.
29///
30/// Booleans record requested mode state; they do not themselves encode input,
31/// paste text, switch screens, or enforce origin/insert behavior.
32///
33/// # Examples
34///
35/// ```
36/// use ailloli_ui_terminal_core::{TerminalModes, TerminalMouseTrackingMode};
37/// let modes = TerminalModes::default();
38/// assert!(modes.wraparound);
39/// assert_eq!(modes.mouse_tracking, TerminalMouseTrackingMode::Off);
40/// ```
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
42pub struct TerminalModes {
43 /// Automatic wrap at the right margin.
44 pub wraparound: bool,
45 /// Insert-mode writes shift existing cells instead of replacing them.
46 pub insert: bool,
47 /// Cursor addressing is relative to the active scroll region.
48 pub origin: bool,
49 /// Pasted text should be enclosed in bracketed-paste delimiters.
50 pub bracketed_paste: bool,
51 /// Cursor keys should use application escape sequences.
52 pub application_cursor: bool,
53 /// Keypad keys should use application escape sequences.
54 pub application_keypad: bool,
55 /// Requested pointer-event reporting policy.
56 pub mouse_tracking: TerminalMouseTrackingMode,
57 /// Mouse reports should use SGR coordinates/encoding.
58 pub sgr_mouse: bool,
59 /// Alternate-screen buffer is active.
60 pub alternate_screen: bool,
61}
62
63impl Default for TerminalModes {
64 fn default() -> Self {
65 Self {
66 wraparound: true,
67 insert: false,
68 origin: false,
69 bracketed_paste: false,
70 application_cursor: false,
71 application_keypad: false,
72 mouse_tracking: TerminalMouseTrackingMode::Off,
73 sgr_mouse: false,
74 alternate_screen: false,
75 }
76 }
77}