aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/kdl
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-04-28 17:14:59 +0200
committerGitHub <noreply@github.com>2026-04-28 17:14:59 +0200
commit227142dd567ee72bcc137c116bc1ce2b818975e7 (patch)
tree8958a994dddb80bf20ce1e6bf2694687736b0b19 /zellij-utils/src/kdl
parentupgrade rustls-webpki (#5106) (diff)
downloadsl0ppij-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/kdl')
-rw-r--r--zellij-utils/src/kdl/mod.rs71
-rw-r--r--zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap11
-rw-r--r--zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap11
3 files changed, 93 insertions, 0 deletions
diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs
index 2b009e1a..c7cc5366 100644
--- a/zellij-utils/src/kdl/mod.rs
+++ b/zellij-utils/src/kdl/mod.rs
@@ -74,6 +74,9 @@ macro_rules! parse_kdl_action_arguments {
"ToggleTab" => Ok(Action::ToggleTab),
"UndoRenameTab" => Ok(Action::UndoRenameTab),
"Detach" => Ok(Action::Detach),
+ "SetDarkTheme" => Ok(Action::SetDarkTheme),
+ "SetLightTheme" => Ok(Action::SetLightTheme),
+ "ToggleTheme" => Ok(Action::ToggleTheme),
"Copy" => Ok(Action::Copy),
"Confirm" => Ok(Action::Confirm),
"Deny" => Ok(Action::Deny),
@@ -2674,6 +2677,10 @@ impl Options {
kdl_property_first_arg_as_bool_or_error!(kdl_options, "auto_layout").map(|(v, _)| v);
let theme = kdl_property_first_arg_as_string_or_error!(kdl_options, "theme")
.map(|(theme, _entry)| theme.to_string());
+ let theme_dark = kdl_property_first_arg_as_string_or_error!(kdl_options, "theme_dark")
+ .map(|(theme, _entry)| theme.to_string());
+ let theme_light = kdl_property_first_arg_as_string_or_error!(kdl_options, "theme_light")
+ .map(|(theme, _entry)| theme.to_string());
let default_mode =
match kdl_property_first_arg_as_string_or_error!(kdl_options, "default_mode") {
Some((string, entry)) => Some(InputMode::from_str(string).map_err(|_| {
@@ -2821,6 +2828,8 @@ impl Options {
Ok(Options {
simplified_ui,
theme,
+ theme_dark,
+ theme_light,
default_mode,
default_shell,
default_cwd,
@@ -2958,6 +2967,62 @@ impl Options {
None
}
}
+ fn theme_dark_to_kdl(&self, add_comments: bool) -> Option<KdlNode> {
+ let comment_text = format!(
+ "{}\n{}\n{}\n{}",
+ " ",
+ "// Theme to use when the host terminal reports a dark color palette.",
+ "// Requires `theme_light` to also be set; otherwise `theme` is used.",
+ "// ",
+ );
+
+ let create_node = |node_value: &str| -> KdlNode {
+ let mut node = KdlNode::new("theme_dark");
+ node.push(node_value.to_owned());
+ node
+ };
+ if let Some(theme) = &self.theme_dark {
+ let mut node = create_node(theme);
+ if add_comments {
+ node.set_leading(format!("{}\n", comment_text));
+ }
+ Some(node)
+ } else if add_comments {
+ let mut node = create_node("dracula");
+ node.set_leading(format!("{}\n// ", comment_text));
+ Some(node)
+ } else {
+ None
+ }
+ }
+ fn theme_light_to_kdl(&self, add_comments: bool) -> Option<KdlNode> {
+ let comment_text = format!(
+ "{}\n{}\n{}\n{}",
+ " ",
+ "// Theme to use when the host terminal reports a light color palette.",
+ "// Requires `theme_dark` to also be set; otherwise `theme` is used.",
+ "// ",
+ );
+
+ let create_node = |node_value: &str| -> KdlNode {
+ let mut node = KdlNode::new("theme_light");
+ node.push(node_value.to_owned());
+ node
+ };
+ if let Some(theme) = &self.theme_light {
+ let mut node = create_node(theme);
+ if add_comments {
+ node.set_leading(format!("{}\n", comment_text));
+ }
+ Some(node)
+ } else if add_comments {
+ let mut node = create_node("solarized-light");
+ node.set_leading(format!("{}\n// ", comment_text));
+ Some(node)
+ } else {
+ None
+ }
+ }
fn default_mode_to_kdl(&self, add_comments: bool) -> Option<KdlNode> {
let comment_text = format!(
"{}\n{}\n{}\n{}",
@@ -4190,6 +4255,12 @@ impl Options {
if let Some(theme_node) = self.theme_to_kdl(add_comments) {
nodes.push(theme_node);
}
+ if let Some(theme_dark_node) = self.theme_dark_to_kdl(add_comments) {
+ nodes.push(theme_dark_node);
+ }
+ if let Some(theme_light_node) = self.theme_light_to_kdl(add_comments) {
+ nodes.push(theme_light_node);
+ }
if let Some(default_mode) = self.default_mode_to_kdl(add_comments) {
nodes.push(default_mode);
}
diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap
index 6dad8aea..c49fa8f9 100644
--- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap
+++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap
@@ -303,6 +303,16 @@ web_client {
//
// theme "dracula"
+// Theme to use when the host terminal reports a dark color palette.
+// Requires `theme_light` to also be set; otherwise `theme` is used.
+//
+// theme_dark "dracula"
+
+// Theme to use when the host terminal reports a light color palette.
+// Requires `theme_dark` to also be set; otherwise `theme` is used.
+//
+// theme_light "solarized-light"
+
// Choose the base input mode of zellij.
// Default: normal
//
@@ -572,3 +582,4 @@ web_client {
// typically work best. Set to 0 to use the number of (physical) CPU cores.
// Note: This only applies to web clients at the moment.
// client_async_worker_tasks 4
+
diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap
index e1f47782..eda40849 100644
--- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap
+++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap
@@ -22,6 +22,16 @@ simplified_ui true
//
theme "dracula"
+// Theme to use when the host terminal reports a dark color palette.
+// Requires `theme_light` to also be set; otherwise `theme` is used.
+//
+// theme_dark "dracula"
+
+// Theme to use when the host terminal reports a light color palette.
+// Requires `theme_dark` to also be set; otherwise `theme` is used.
+//
+// theme_light "solarized-light"
+
// Choose the base input mode of zellij.
// Default: normal
//
@@ -291,3 +301,4 @@ web_sharing "disabled"
// typically work best. Set to 0 to use the number of (physical) CPU cores.
// Note: This only applies to web clients at the moment.
// client_async_worker_tasks 4
+