1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use nix::pty::Winsize;
use serde::{Deserialize, Serialize};

/// Contains the position and size of a [`Pane`], or more generally of any terminal, measured
/// in character rows and columns.
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
pub struct PositionAndSize {
    pub x: usize,
    pub y: usize,
    pub rows: usize,
    pub cols: usize,
    // FIXME: Honestly, these shouldn't exist and rows / columns should be enums like:
    // Dimension::Flex(usize) / Dimension::Fixed(usize), but 400+ compiler errors is more than
    // I'm in the mood for right now...
    pub rows_fixed: bool,
    pub cols_fixed: bool,
}

impl From<Winsize> for PositionAndSize {
    fn from(winsize: Winsize) -> PositionAndSize {
        PositionAndSize {
            cols: winsize.ws_col as usize,
            rows: winsize.ws_row as usize,
            ..Default::default()
        }
    }
}