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
28
29
30
31
32
33
34
35
pub enum TerminalSizeType {
    Character,
    Pixel,
}

pub struct TerminalSize {
    width: u32,
    height: u32,
    type_: TerminalSizeType,
}

impl TerminalSize {
    pub fn from(width: u32, height: u32) -> Self {
        TerminalSize {
            width,
            height,
            type_: TerminalSizeType::Character,
        }
    }

    pub fn from_type(width: u32, height: u32, type_: TerminalSizeType) -> Self {
        TerminalSize {
            width,
            height,
            type_,
        }
    }

    pub(crate) fn fetch(&self) -> (u32, u32, u32, u32) {
        match self.type_ {
            TerminalSizeType::Character => (self.width, self.height, 0, 0),
            TerminalSizeType::Pixel => (0, 0, self.width, self.height),
        }
    }
}