aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/input
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-11 00:12:10 +0200
committeruser <user@clank>2026-08-11 00:12:10 +0200
commit393748bb2fb0ad741f2d51cfe0f8db75cf2ad7c3 (patch)
tree09a651d4640e18398df90cdac0857e8602bcd5a0 /zellij-utils/src/input
parentsl0p: refresh snapshots for the compact scroll indicator (diff)
downloadsl0ppij-393748bb2fb0ad741f2d51cfe0f8db75cf2ad7c3.tar.gz
sl0ppij-393748bb2fb0ad741f2d51cfe0f8db75cf2ad7c3.tar.xz
sl0ppij-393748bb2fb0ad741f2d51cfe0f8db75cf2ad7c3.zip
sl0p: collapse to a swap layout when the terminal gets narrow
Splitting a window into thirds is great until the window is 70 columns wide and each pane gets 23. `responsive_min_cols` collapses the tab into the swap layout named by `responsive_layout` when it gets narrower than that, and restores the previously active layout when it grows back. Selects a swap layout BY NAME rather than adding a size-aware LayoutConstraint: that type crosses both the plugin protobuf API and the client/server contract, and the committed prost assets cannot be regenerated here (no protoc). Restoring uses a 10-column hysteresis band. Without a dead band, dragging a window edge that lands exactly on the threshold flips the layout on every motion event, and every flip resizes every PTY in the tab. "Did the user rearrange panes by hand" is judged from the damaged flag as sampled BEFORE each resize, not the live one: resize_whole_tab's own auto-layout pass sets that flag itself and clears it again only if it found a layout that fits, so on a terminal too narrow for any of them it latches true although nothing was rearranged. And once collapsed, restore stays reachable regardless of the flag, so damage occurring while collapsed cannot strand the tab in the narrow layout.
Diffstat (limited to 'zellij-utils/src/input')
-rw-r--r--zellij-utils/src/input/config.rs23
-rw-r--r--zellij-utils/src/input/theme.rs13
2 files changed, 34 insertions, 2 deletions
diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs
index 7b870332..3a105937 100644
--- a/zellij-utils/src/input/config.rs
+++ b/zellij-utils/src/input/config.rs
@@ -1438,6 +1438,27 @@ mod config_test {
}
#[test]
+ fn responsive_layout_options_are_configurable() {
+ let contents =
+ "ui {\n pane_frames {\n responsive_min_cols 90\n responsive_layout \"squished\"\n }\n}";
+ let frames = Config::from_kdl(contents, None).unwrap().ui.pane_frames;
+ assert_eq!(frames.responsive_min_cols, 90);
+ assert_eq!(frames.responsive_layout, "squished");
+ }
+
+ #[test]
+ fn negative_responsive_min_cols_clamps_to_disabled() {
+ // parsed as i64 then clamped: a negative threshold is meaningless and
+ // must not wrap around to a huge usize, which would collapse always
+ let contents = "ui {\n pane_frames {\n responsive_min_cols -5\n }\n}";
+ let frames = Config::from_kdl(contents, None).unwrap().ui.pane_frames;
+ assert_eq!(
+ frames.responsive_min_cols, 0,
+ "negative min_cols must clamp to 0 (feature off), not wrap"
+ );
+ }
+
+ #[test]
fn can_define_ui_configuration_in_configfile() {
let config_contents = r#"
ui {
@@ -1458,6 +1479,8 @@ mod config_test {
gap_aspect: 2, // parser default; see FrameConfig::default()
inactive_grayscale: 0,
hide_default_pane_names: false,
+ responsive_min_cols: 0,
+ responsive_layout: String::from("stacked"),
},
};
assert_eq!(config.ui, expected_ui_config, "Ui config defined in config");
diff --git a/zellij-utils/src/input/theme.rs b/zellij-utils/src/input/theme.rs
index 45ae763b..161eb16d 100644
--- a/zellij-utils/src/input/theme.rs
+++ b/zellij-utils/src/input/theme.rs
@@ -9,7 +9,7 @@ use std::{
use crate::data::Styling;
-#[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize)]
+#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
pub struct UiConfig {
pub pane_frames: FrameConfig,
}
@@ -22,7 +22,7 @@ impl UiConfig {
}
}
-#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
+#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct FrameConfig {
pub rounded_corners: bool,
pub hide_session_name: bool,
@@ -43,6 +43,11 @@ pub struct FrameConfig {
/// Omit the auto-generated "Pane #N" placeholder title, so a pane shows no
/// name until the user sets one or the running program sets a title.
pub hide_default_pane_names: bool,
+ /// Collapse to the swap layout named `responsive_layout` when the terminal
+ /// is narrower than this many columns. 0 disables the whole feature.
+ pub responsive_min_cols: usize,
+ /// Name of the swap tiled layout to use when below the threshold.
+ pub responsive_layout: String,
}
/// Hand-written rather than derived: `gap_aspect` must default to 2 to match
@@ -60,6 +65,8 @@ impl Default for FrameConfig {
gap_aspect: 2,
inactive_grayscale: 0,
hide_default_pane_names: false,
+ responsive_min_cols: 0,
+ responsive_layout: String::from("stacked"),
}
}
}
@@ -88,6 +95,8 @@ impl FrameConfig {
merged.gap_aspect = other.gap_aspect;
merged.inactive_grayscale = other.inactive_grayscale;
merged.hide_default_pane_names = other.hide_default_pane_names;
+ merged.responsive_min_cols = other.responsive_min_cols;
+ merged.responsive_layout = other.responsive_layout.clone();
merged
}
}