vtcode_ghostty_core/
mode.rs1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3pub enum CursorShape {
4 Block,
5 Underline,
6 Bar,
7}
8
9impl Default for CursorShape {
10 fn default() -> Self {
11 Self::Block
12 }
13}
14
15#[derive(Clone, Copy, Debug, Eq, PartialEq)]
17pub enum MouseTracking {
18 Button,
19 Drag,
20 Any,
21}
22
23#[derive(Clone, Debug)]
25pub(crate) struct TerminalModes {
26 pub(crate) wraparound: bool,
27 pub(crate) cursor_visible: bool,
28 pub(crate) cursor_shape: CursorShape,
29 pub(crate) application_cursor_keys: bool,
30 pub(crate) bracketed_paste: bool,
31 pub(crate) focus_reporting: bool,
32 pub(crate) mouse_tracking: Option<MouseTracking>,
33 pub(crate) sgr_mouse: bool,
34}
35
36impl Default for TerminalModes {
37 fn default() -> Self {
38 Self {
39 wraparound: true,
40 cursor_visible: true,
41 cursor_shape: CursorShape::Block,
42 application_cursor_keys: false,
43 bracketed_paste: false,
44 focus_reporting: false,
45 mouse_tracking: None,
46 sgr_mouse: false,
47 }
48 }
49}
50
51impl TerminalModes {
52 pub(crate) fn set_private_mode(&mut self, mode: usize, enabled: bool) -> bool {
54 match mode {
55 1 => {
56 self.application_cursor_keys = enabled;
57 true
58 }
59 7 => {
60 self.wraparound = enabled;
61 true
62 }
63 25 => {
64 self.cursor_visible = enabled;
65 true
66 }
67 1000 => {
68 self.mouse_tracking = if enabled {
69 Some(MouseTracking::Button)
70 } else {
71 None
72 };
73 true
74 }
75 1002 => {
76 self.mouse_tracking = if enabled {
77 Some(MouseTracking::Drag)
78 } else {
79 None
80 };
81 true
82 }
83 1003 => {
84 self.mouse_tracking = if enabled {
85 Some(MouseTracking::Any)
86 } else {
87 None
88 };
89 true
90 }
91 1004 => {
92 self.focus_reporting = enabled;
93 true
94 }
95 1006 => {
96 self.sgr_mouse = enabled;
97 true
98 }
99 2004 => {
100 self.bracketed_paste = enabled;
101 true
102 }
103 _ => false,
104 }
105 }
106
107 pub(crate) fn set_cursor_shape(&mut self, param: usize) {
109 self.cursor_shape = match param {
110 3 | 4 => CursorShape::Underline,
111 5 | 6 => CursorShape::Bar,
112 _ => CursorShape::Block,
113 };
114 }
115}