pty_process/
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(
27        row: u16,
28        col: u16,
29        xpixel: u16,
30        ypixel: u16,
31    ) -> Self {
32        Self {
33            row,
34            col,
35            xpixel,
36            ypixel,
37        }
38    }
39}
40
41impl From<Size> for rustix::termios::Winsize {
42    fn from(size: Size) -> Self {
43        Self {
44            ws_row: size.row,
45            ws_col: size.col,
46            ws_xpixel: size.xpixel,
47            ws_ypixel: size.ypixel,
48        }
49    }
50}