diff options
| author | user <user@clank> | 2026-08-08 19:31:55 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-08 19:31:55 +0200 |
| commit | 3f767ee91b08eebf10b693c08c173b8329ba2c14 (patch) | |
| tree | 6f2b7feed0f454f8a6036fbef54b2d647f35462d /zellij-utils/src | |
| parent | sl0p: rebuilt default plugin wasm assets (diff) | |
| download | sl0ppij-3f767ee91b08eebf10b693c08c173b8329ba2c14.tar.gz sl0ppij-3f767ee91b08eebf10b693c08c173b8329ba2c14.tar.xz sl0ppij-3f767ee91b08eebf10b693c08c173b8329ba2c14.zip | |
sl0p: configurable pane title alignment
Adds `ui { pane_frames { title_alignment "left"|"center"|"right" } }`.
Full-frame panes previously hardcoded the title flush left, while frameless
panes (pane_frame_style "titles") already centered it via
compose_bracketed_title. This brings full frames up to parity and makes the
position configurable.
Implementation notes:
- The value rides on `Style`, which is already threaded to FrameParams, so no
new plumbing through Tab/PaneContentsAndUi was needed.
- It is deliberately NOT round-tripped over the plugin protobuf boundary:
plugins have no use for frame title alignment and adding a proto field
would force regenerating the committed prost assets in assets/prost/.
- Left keeps the original code path untouched, so default configs render
exactly as before.
- The geometry loop clamps the title start against the right-side indicators
and breaks on `>=` rather than `==`, so a mis-clamped segment cannot spin.
Tests: alignment ordering, frame width preservation across widths, and
narrow-pane safety (cols 1..24 must not panic or corrupt width).
Diffstat (limited to 'zellij-utils/src')
| -rw-r--r-- | zellij-utils/src/data.rs | 34 | ||||
| -rw-r--r-- | zellij-utils/src/input/config.rs | 1 | ||||
| -rw-r--r-- | zellij-utils/src/input/theme.rs | 2 | ||||
| -rw-r--r-- | zellij-utils/src/kdl/mod.rs | 25 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/event.rs | 1 | ||||
| -rw-r--r-- | zellij-utils/src/plugin_api/style.rs | 5 |
6 files changed, 68 insertions, 0 deletions
diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 12e66002..f4ce534f 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -1384,11 +1384,45 @@ pub struct Palette { pub brown: PaletteColor, } +/// Where the pane title sits inside a pane's frame. +/// +/// NOTE: this currently only affects panes drawn with FULL frames. In frameless +/// (`pane_frame_style "titles"`) mode the title goes through +/// `compose_bracketed_title`, which already centers it unconditionally. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum PaneTitleAlignment { + #[default] + Left, + Center, + Right, +} + +impl std::str::FromStr for PaneTitleAlignment { + type Err = String; + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s.trim().to_lowercase().as_str() { + "left" => Ok(PaneTitleAlignment::Left), + "center" | "centre" => Ok(PaneTitleAlignment::Center), + "right" => Ok(PaneTitleAlignment::Right), + e => Err(format!( + "Unknown pane title alignment: '{}' (expected 'left', 'center' or 'right')", + e + )), + } + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub struct Style { pub colors: Styling, pub rounded_corners: bool, pub hide_session_name: bool, + /// NOT round-tripped through the plugin protobuf API on purpose: plugins + /// have no use for it and adding a proto field would force regenerating + /// the committed prost assets. Defaults to Left when coming back from a + /// ProtobufStyle. + pub pane_title_alignment: PaneTitleAlignment, } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index 1b917864..9387aef3 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -1407,6 +1407,7 @@ mod config_test { pane_frames: FrameConfig { rounded_corners: true, hide_session_name: true, + title_alignment: Default::default(), }, }; 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 b4fbc630..0930bc15 100644 --- a/zellij-utils/src/input/theme.rs +++ b/zellij-utils/src/input/theme.rs @@ -26,6 +26,7 @@ impl UiConfig { pub struct FrameConfig { pub rounded_corners: bool, pub hide_session_name: bool, + pub title_alignment: crate::data::PaneTitleAlignment, } impl FrameConfig { @@ -33,6 +34,7 @@ impl FrameConfig { let mut merged = self.clone(); merged.rounded_corners = other.rounded_corners; merged.hide_session_name = other.hide_session_name; + merged.title_alignment = other.title_alignment; merged } } diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index 8e86445f..bc188aed 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -5524,9 +5524,21 @@ impl UiConfig { .unwrap_or(false); let hide_session_name = kdl_get_child_entry_bool_value!(pane_frames, "hide_session_name").unwrap_or(false); + let title_alignment = match kdl_children_property_first_arg_as_string!( + pane_frames, + "title_alignment" + ) { + Some(string) => { + crate::data::PaneTitleAlignment::from_str(string).map_err(|e| { + ConfigError::new_kdl_error(e, kdl_ui_config.span().offset(), kdl_ui_config.span().len()) + })? + }, + None => crate::data::PaneTitleAlignment::default(), + }; let frame_config = FrameConfig { rounded_corners, hide_session_name, + title_alignment, }; ui_config.pane_frames = frame_config; } @@ -5550,6 +5562,19 @@ impl UiConfig { hide_session_name.push(KdlValue::Bool(true)); frame_config_children.nodes_mut().push(hide_session_name); } + if self.pane_frames.title_alignment != crate::data::PaneTitleAlignment::default() { + has_ui_config = true; + let mut title_alignment = KdlNode::new("title_alignment"); + title_alignment.push(KdlValue::String( + match self.pane_frames.title_alignment { + crate::data::PaneTitleAlignment::Left => "left", + crate::data::PaneTitleAlignment::Center => "center", + crate::data::PaneTitleAlignment::Right => "right", + } + .to_string(), + )); + frame_config_children.nodes_mut().push(title_alignment); + } if has_ui_config { frame_config.set_children(frame_config_children); ui_config_children.nodes_mut().push(frame_config); diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs index 970f5e2c..0189d11b 100644 --- a/zellij-utils/src/plugin_api/event.rs +++ b/zellij-utils/src/plugin_api/event.rs @@ -2492,6 +2492,7 @@ fn serialize_mode_update_event_with_non_default_values() { // TODO: replace default rounded_corners: true, hide_session_name: false, + pane_title_alignment: Default::default(), }, capabilities: PluginCapabilities { arrow_fonts: false }, session_name: Some("my awesome test session".to_owned()), diff --git a/zellij-utils/src/plugin_api/style.rs b/zellij-utils/src/plugin_api/style.rs index eb9eebcf..2f3ff298 100644 --- a/zellij-utils/src/plugin_api/style.rs +++ b/zellij-utils/src/plugin_api/style.rs @@ -21,6 +21,11 @@ impl TryFrom<ProtobufStyle> for Style { colors: s, rounded_corners: protobuf_style.rounded_corners, hide_session_name: protobuf_style.hide_session_name, + // deliberately not carried over the plugin protobuf boundary; see + // the field docs on Style. Plugins never need the frame's title + // alignment, and adding a proto field would mean regenerating the + // committed prost assets. + pane_title_alignment: Default::default(), }) } } |
