From 15539d3dec40bcc40e6f4bb0eaa4f073ad26b74f Mon Sep 17 00:00:00 2001 From: Can Celik Date: Sat, 15 Aug 2026 15:09:53 +0300 Subject: feat: make headless terminal size configurable (#2829) refs #2828 --- src/config/io.rs | 9 +++++++++ src/config/model.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) (limited to 'src/config') diff --git a/src/config/io.rs b/src/config/io.rs index 7ed82395..898cf077 100644 --- a/src/config/io.rs +++ b/src/config/io.rs @@ -10,6 +10,7 @@ const KNOWN_TOP_LEVEL_CONFIG_KEYS: &[&str] = &[ "keys", "onboarding", "remote", + "server", "session", "terminal", "theme", @@ -292,6 +293,14 @@ fn load_live_config_from_str(content: &str) -> Result> &mut invalid_sections, |section| config.session = section, ); + load_live_section( + table, + "server", + "server config", + &mut diagnostics, + &mut invalid_sections, + |section| config.server = section, + ); load_live_section( table, "update", diff --git a/src/config/model.rs b/src/config/model.rs index 6d6083ad..ad779d26 100644 --- a/src/config/model.rs +++ b/src/config/model.rs @@ -315,6 +315,7 @@ pub struct Config { pub theme: ThemeConfig, pub terminal: TerminalConfig, pub session: SessionConfig, + pub server: ServerConfig, pub update: UpdateConfig, pub keys: KeysConfig, pub ui: UiConfig, @@ -938,6 +939,15 @@ impl ImeCursorShape { } } +#[derive(Debug, Deserialize)] +#[serde(default)] +pub struct ServerConfig { + /// Virtual terminal width used when no client is attached. Default: 120. + pub headless_cols: u16, + /// Virtual terminal height used when no client is attached. Default: 40. + pub headless_rows: u16, +} + #[derive(Debug, Deserialize)] #[serde(default)] pub struct AdvancedConfig { @@ -1200,6 +1210,15 @@ impl<'de> Deserialize<'de> for ToastConfig { } } +impl Default for ServerConfig { + fn default() -> Self { + Self { + headless_cols: crate::config::DEFAULT_HEADLESS_COLS, + headless_rows: crate::config::DEFAULT_HEADLESS_ROWS, + } + } +} + impl Default for AdvancedConfig { fn default() -> Self { Self { @@ -1817,6 +1836,45 @@ delay_seconds = {} assert!(!config.should_show_onboarding()); } + #[test] + fn server_headless_size_defaults_and_parses() { + let default_config = Config::default(); + assert_eq!( + default_config.server.headless_cols, + crate::config::DEFAULT_HEADLESS_COLS + ); + assert_eq!( + default_config.server.headless_rows, + crate::config::DEFAULT_HEADLESS_ROWS + ); + + let config: Config = toml::from_str( + r#"[server] +headless_cols = 160 +headless_rows = 50 +"#, + ) + .unwrap(); + assert_eq!(config.server.headless_cols, 160); + assert_eq!(config.server.headless_rows, 50); + + let invalid: Config = toml::from_str( + r#"[server] +headless_cols = 0 +headless_rows = 50 +"#, + ) + .unwrap(); + assert!(invalid.invalid_headless_size_diagnostic().is_some()); + assert_eq!( + invalid.headless_size(), + ( + crate::config::DEFAULT_HEADLESS_COLS, + crate::config::DEFAULT_HEADLESS_ROWS + ) + ); + } + #[test] fn advanced_defaults_include_scrollback_limit_bytes() { let config = Config::default(); -- cgit v1.2.3