gpui_cn/terminal/
options.rs1use std::collections::BTreeMap;
4use std::path::PathBuf;
5use std::time::Duration;
6
7#[derive(Clone, Debug, PartialEq, Eq)]
11#[non_exhaustive]
12pub struct EngineOptions {
13 pub(crate) scrollback_bytes: usize,
15 pub(crate) scrollback_lines: Option<usize>,
17 pub(crate) terminfo_name: String,
19 pub(crate) clipboard_write_max_bytes: usize,
21 pub(crate) park: crate::terminal::park::ParkOptions,
22}
23
24impl Default for EngineOptions {
25 fn default() -> Self {
26 Self {
27 scrollback_bytes: 10_000_000,
28 scrollback_lines: None,
29 terminfo_name: ghostty_vt::terminfo::TERM.to_owned(),
30 clipboard_write_max_bytes: 64 << 20,
31 park: crate::terminal::park::ParkOptions::default(),
32 }
33 }
34}
35
36impl EngineOptions {
37 #[must_use]
39 pub fn with_scrollback_bytes(mut self, bytes: usize) -> Self {
40 self.scrollback_bytes = bytes;
41 self
42 }
43
44 #[must_use]
46 pub fn with_scrollback_lines(mut self, lines: Option<usize>) -> Self {
47 self.scrollback_lines = lines;
48 self
49 }
50
51 #[must_use]
53 pub fn with_terminfo_name(mut self, name: impl Into<String>) -> Self {
54 self.terminfo_name = name.into();
55 self
56 }
57
58 #[must_use]
60 pub fn with_clipboard_write_max_bytes(mut self, bytes: usize) -> Self {
61 self.clipboard_write_max_bytes = bytes;
62 self
63 }
64
65 #[must_use]
69 pub fn with_park(mut self, park: crate::terminal::park::ParkOptions) -> Self {
70 self.park = park;
71 self
72 }
73
74 pub fn park(&self) -> &crate::terminal::park::ParkOptions {
76 &self.park
77 }
78
79 pub fn scrollback_bytes(&self) -> usize {
81 self.scrollback_bytes
82 }
83
84 pub fn scrollback_lines(&self) -> Option<usize> {
86 self.scrollback_lines
87 }
88
89 pub fn terminfo_name(&self) -> &str {
91 &self.terminfo_name
92 }
93
94 pub fn clipboard_write_max_bytes(&self) -> usize {
96 self.clipboard_write_max_bytes
97 }
98}
99
100#[derive(Clone, Debug, Default, PartialEq, Eq)]
102pub enum WorkingDirectory {
103 #[default]
105 Inherit,
106 Home,
108 Path(PathBuf),
110}
111
112#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
114pub enum ShellIntegration {
115 #[default]
117 Detect,
118 None,
120 Bash,
122 Zsh,
124 Fish,
126 Elvish,
128 Nushell,
130}
131
132#[derive(Clone, Debug, PartialEq, Eq)]
134#[non_exhaustive]
135pub struct LocalTerminalOptions {
136 pub(crate) engine: EngineOptions,
138 pub(crate) program: Option<PathBuf>,
140 pub(crate) args: Vec<String>,
142 pub(crate) cwd: WorkingDirectory,
144 pub(crate) env: BTreeMap<String, String>,
146 pub(crate) env_remove: Vec<String>,
148 pub(crate) input: Vec<u8>,
150 pub(crate) shell_integration: ShellIntegration,
152 pub(crate) shell_integration_features: Vec<String>,
154 pub(crate) login: bool,
156 pub(crate) abnormal_exit_runtime: Duration,
158}
159
160impl Default for LocalTerminalOptions {
161 fn default() -> Self {
162 Self {
163 engine: EngineOptions::default(),
164 program: None,
165 args: Vec::new(),
166 cwd: WorkingDirectory::Inherit,
167 env: BTreeMap::new(),
168 env_remove: Vec::new(),
169 input: Vec::new(),
170 shell_integration: ShellIntegration::Detect,
171 shell_integration_features: vec![
172 "cursor".to_owned(),
173 "sudo".to_owned(),
174 "title".to_owned(),
175 ],
176 login: true,
177 abnormal_exit_runtime: Duration::from_millis(250),
178 }
179 }
180}
181
182impl LocalTerminalOptions {
183 #[must_use]
185 pub fn with_program(
186 mut self,
187 program: impl Into<PathBuf>,
188 args: impl IntoIterator<Item = impl Into<String>>,
189 ) -> Self {
190 self.program = Some(program.into());
191 self.args = args.into_iter().map(Into::into).collect();
192 self
193 }
194
195 #[must_use]
197 pub fn with_cwd(mut self, cwd: WorkingDirectory) -> Self {
198 self.cwd = cwd;
199 self
200 }
201
202 #[must_use]
204 pub fn with_env(mut self, name: impl Into<String>, value: impl Into<String>) -> Self {
205 self.env.insert(name.into(), value.into());
206 self
207 }
208
209 #[must_use]
211 pub fn with_shell_integration(mut self, integration: ShellIntegration) -> Self {
212 self.shell_integration = integration;
213 self
214 }
215
216 #[must_use]
218 pub fn with_engine(mut self, engine: EngineOptions) -> Self {
219 self.engine = engine;
220 self
221 }
222
223 #[must_use]
225 pub fn with_login(mut self, login: bool) -> Self {
226 self.login = login;
227 self
228 }
229
230 #[must_use]
232 pub fn with_input(mut self, input: impl Into<Vec<u8>>) -> Self {
233 self.input = input.into();
234 self
235 }
236
237 #[must_use]
239 pub fn without_env(mut self, name: impl Into<String>) -> Self {
240 self.env_remove.push(name.into());
241 self
242 }
243
244 #[must_use]
246 pub fn with_shell_integration_features(
247 mut self,
248 features: impl IntoIterator<Item = impl Into<String>>,
249 ) -> Self {
250 self.shell_integration_features = features.into_iter().map(Into::into).collect();
251 self
252 }
253
254 #[must_use]
256 pub fn with_abnormal_exit_runtime(mut self, runtime: Duration) -> Self {
257 self.abnormal_exit_runtime = runtime;
258 self
259 }
260
261 pub fn engine(&self) -> &EngineOptions {
263 &self.engine
264 }
265
266 pub fn program(&self) -> Option<&std::path::Path> {
268 self.program.as_deref()
269 }
270
271 pub fn args(&self) -> &[String] {
273 &self.args
274 }
275
276 pub fn cwd(&self) -> &WorkingDirectory {
278 &self.cwd
279 }
280
281 pub fn env(&self) -> &BTreeMap<String, String> {
283 &self.env
284 }
285
286 pub fn env_remove(&self) -> &[String] {
288 &self.env_remove
289 }
290
291 pub fn input(&self) -> &[u8] {
293 &self.input
294 }
295
296 pub fn shell_integration(&self) -> ShellIntegration {
298 self.shell_integration
299 }
300
301 pub fn shell_integration_features(&self) -> &[String] {
303 &self.shell_integration_features
304 }
305
306 pub fn login(&self) -> bool {
308 self.login
309 }
310
311 pub fn abnormal_exit_runtime(&self) -> Duration {
313 self.abnormal_exit_runtime
314 }
315}
316
317#[cfg(test)]
318mod tests {
319 #[test]
320 fn the_scrollback_limit_is_ghosttys_default() {
321 assert_eq!(
322 super::EngineOptions::default().scrollback_bytes(),
323 10_000_000
324 );
325 }
326}