Skip to main content

tear_types/
direction.rs

1//! Pane split direction + orientation.
2
3use serde::{Deserialize, Serialize};
4
5/// Direction a new pane appears relative to its split origin.
6#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum Direction {
9    /// Above the originating pane (creates a Horizontal split — the
10    /// terminology mirrors tmux's `split-window -b -v`).
11    Above,
12    /// Below the originating pane (default for tmux's `C-b "`).
13    Below,
14    /// Left of the originating pane.
15    Left,
16    /// Right of the originating pane (default for tmux's `C-b %`).
17    Right,
18}
19
20impl Direction {
21    /// The split orientation this direction creates. A new pane to
22    /// the right introduces a vertical split (the cells of cells are
23    /// arranged side by side); above/below introduces a horizontal
24    /// split (stacked rows).
25    #[must_use]
26    pub const fn orientation(self) -> SplitOrientation {
27        match self {
28            Self::Above | Self::Below => SplitOrientation::Horizontal,
29            Self::Left | Self::Right => SplitOrientation::Vertical,
30        }
31    }
32}
33
34/// How a [`crate::LayoutNode::Split`] divides its area.
35///
36/// "Horizontal" splits stack panes vertically (one above the other);
37/// "Vertical" splits sit side by side. This matches the tmux
38/// terminology where `split-window -h` produces side-by-side and
39/// `split-window -v` produces top-and-bottom. mado uses the same
40/// definitions internally; the shared types keep both apps consistent.
41#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
42#[serde(rename_all = "lowercase")]
43pub enum SplitOrientation {
44    Horizontal,
45    Vertical,
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn direction_orientation_matches_tmux_semantics() {
54        assert_eq!(Direction::Above.orientation(), SplitOrientation::Horizontal);
55        assert_eq!(Direction::Below.orientation(), SplitOrientation::Horizontal);
56        assert_eq!(Direction::Left.orientation(), SplitOrientation::Vertical);
57        assert_eq!(Direction::Right.orientation(), SplitOrientation::Vertical);
58    }
59}