Skip to main content

prek_pty/
types.rs

1/// Represents the size of the pty.
2#[derive(Debug, Clone, Copy)]
3pub struct Size {
4    row: u16,
5    col: u16,
6    xpixel: u16,
7    ypixel: u16,
8}
9
10impl Size {
11    /// Returns a [`Size`](Size) instance with the given number of rows and
12    /// columns.
13    #[must_use]
14    pub fn new(row: u16, col: u16) -> Self {
15        Self {
16            row,
17            col,
18            xpixel: 0,
19            ypixel: 0,
20        }
21    }
22
23    /// Returns a [`Size`](Size) instance with the given number of rows and
24    /// columns, as well as the given pixel dimensions.
25    #[must_use]
26    pub fn new_with_pixel(row: u16, col: u16, xpixel: u16, ypixel: u16) -> Self {
27        Self {
28            row,
29            col,
30            xpixel,
31            ypixel,
32        }
33    }
34}
35
36impl From<Size> for rustix::termios::Winsize {
37    fn from(size: Size) -> Self {
38        Self {
39            ws_row: size.row,
40            ws_col: size.col,
41            ws_xpixel: size.xpixel,
42            ws_ypixel: size.ypixel,
43        }
44    }
45}