diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-04-28 17:14:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-28 17:14:59 +0200 |
| commit | 227142dd567ee72bcc137c116bc1ce2b818975e7 (patch) | |
| tree | 8958a994dddb80bf20ce1e6bf2694687736b0b19 /zellij-utils/src/input | |
| parent | upgrade rustls-webpki (#5106) (diff) | |
| download | sl0ppij-227142dd567ee72bcc137c116bc1ce2b818975e7.tar.gz sl0ppij-227142dd567ee72bcc137c116bc1ce2b818975e7.tar.xz sl0ppij-227142dd567ee72bcc137c116bc1ce2b818975e7.zip | |
Support CSI2031 (dark/light theme switching) + remove STDIN cache to avoid stale color queries (#5105)
* initial phase 1 implementation
* various fies
* some fixes
* fix fragmented stdin cases
* some fixes
* renaming
* guard against old clients
* implement csi 2031
* allow toggling theme with actions
* rustfmt
* fix: finalize trailing characters in ansi parser as well
* add pr
Diffstat (limited to 'zellij-utils/src/input')
| -rw-r--r-- | zellij-utils/src/input/actions.rs | 45 | ||||
| -rw-r--r-- | zellij-utils/src/input/options.rs | 18 |
2 files changed, 63 insertions, 0 deletions
diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index ab4c9ae3..7f6fabfe 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -353,6 +353,12 @@ pub enum Action { }, /// Detach session and exit Detach, + /// Switch the host-terminal theme mode to dark (uses configured `theme_dark`). + SetDarkTheme, + /// Switch the host-terminal theme mode to light (uses configured `theme_light`). + SetLightTheme, + /// Toggle between dark and light host-terminal theme modes. + ToggleTheme, /// Switch to a different session SwitchSession { name: String, @@ -2052,6 +2058,9 @@ impl Action { } }, CliAction::Detach => Ok(vec![Action::Detach]), + CliAction::SetDarkTheme => Ok(vec![Action::SetDarkTheme]), + CliAction::SetLightTheme => Ok(vec![Action::SetLightTheme]), + CliAction::ToggleTheme => Ok(vec![Action::ToggleTheme]), CliAction::SwitchSession { name, tab_position, @@ -3053,6 +3062,42 @@ mod tests { assert!(matches!(actions[0], Action::CloseTab)); } + #[test] + fn test_set_dark_theme_cli_to_action() { + let result = Action::actions_from_cli( + CliAction::SetDarkTheme, + Box::new(|| PathBuf::from("/tmp")), + None, + ); + let actions = result.expect("SetDarkTheme conversion should succeed"); + assert_eq!(actions.len(), 1); + assert!(matches!(actions[0], Action::SetDarkTheme)); + } + + #[test] + fn test_set_light_theme_cli_to_action() { + let result = Action::actions_from_cli( + CliAction::SetLightTheme, + Box::new(|| PathBuf::from("/tmp")), + None, + ); + let actions = result.expect("SetLightTheme conversion should succeed"); + assert_eq!(actions.len(), 1); + assert!(matches!(actions[0], Action::SetLightTheme)); + } + + #[test] + fn test_toggle_theme_cli_to_action() { + let result = Action::actions_from_cli( + CliAction::ToggleTheme, + Box::new(|| PathBuf::from("/tmp")), + None, + ); + let actions = result.expect("ToggleTheme conversion should succeed"); + assert_eq!(actions.len(), 1); + assert!(matches!(actions[0], Action::ToggleTheme)); + } + // 21. RenameTab #[test] fn test_rename_tab_with_tab_id() { diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index bb90b7b1..854ef271 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -48,6 +48,16 @@ pub struct Options { /// Set the default theme #[clap(long, value_parser)] pub theme: Option<String>, + /// Theme name to apply when the host terminal reports a dark color palette + /// (CSI 2031 / DSR 997). Requires `theme_light` to also be set; if either + /// is missing the static `theme` remains authoritative. + #[clap(long, value_parser)] + pub theme_dark: Option<String>, + /// Theme name to apply when the host terminal reports a light color palette + /// (CSI 2031 / DSR 997). Requires `theme_dark` to also be set; if either + /// is missing the static `theme` remains authoritative. + #[clap(long, value_parser)] + pub theme_light: Option<String>, /// Set the default mode #[clap(long, arg_enum, hide_possible_values = true, value_parser)] pub default_mode: Option<InputMode>, @@ -319,6 +329,8 @@ impl Options { let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone()); let theme_dir = other.theme_dir.or_else(|| self.theme_dir.clone()); let theme = other.theme.or_else(|| self.theme.clone()); + let theme_dark = other.theme_dark.or_else(|| self.theme_dark.clone()); + let theme_light = other.theme_light.or_else(|| self.theme_light.clone()); let on_force_close = other.on_force_close.or(self.on_force_close); let scroll_buffer_size = other.scroll_buffer_size.or(self.scroll_buffer_size); let copy_command = other.copy_command.or_else(|| self.copy_command.clone()); @@ -376,6 +388,8 @@ impl Options { Options { simplified_ui, theme, + theme_dark, + theme_light, default_mode, default_shell, default_cwd, @@ -454,6 +468,8 @@ impl Options { let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone()); let theme_dir = other.theme_dir.or_else(|| self.theme_dir.clone()); let theme = other.theme.or_else(|| self.theme.clone()); + let theme_dark = other.theme_dark.or_else(|| self.theme_dark.clone()); + let theme_light = other.theme_light.or_else(|| self.theme_light.clone()); let on_force_close = other.on_force_close.or(self.on_force_close); let scroll_buffer_size = other.scroll_buffer_size.or(self.scroll_buffer_size); let copy_command = other.copy_command.or_else(|| self.copy_command.clone()); @@ -507,6 +523,8 @@ impl Options { Options { simplified_ui, theme, + theme_dark, + theme_light, default_mode, default_shell, default_cwd, |
