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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

use {
    crate::*,
    crate::crossterm::{
        QueueableCommand,
        style::Print,
    },
    std::io::Write,
};

const FILLING_STRING_CHAR_LEN: usize = 1000;

/// something to fill with
pub struct Filling {
    filling_string: String,
    char_size: usize,
}

impl Filling {
    pub fn from_char(filling_char: char) -> Self {
        let char_size = String::from(filling_char).len();
        let mut filling_string = String::with_capacity(char_size * FILLING_STRING_CHAR_LEN);
        for _ in 0..FILLING_STRING_CHAR_LEN {
            filling_string.push(filling_char);
        }
        Self {
            filling_string,
            char_size,
        }
    }
    pub fn queue_unstyled<W: Write>(
        &self,
        w: &mut W,
        mut len: usize,
    ) -> Result<(), Error> {
        while len > 0 {
            let sl = len.min(FILLING_STRING_CHAR_LEN);
            w.queue(Print(&self.filling_string[0..sl * self.char_size]))?;
            len -= sl;
        }
        Ok(())
    }
    pub fn queue_styled<W: Write>(
        &self,
        w: &mut W,
        cs: &CompoundStyle,
        mut len: usize,
    ) -> Result<(), Error> {
        while len > 0 {
            let sl = len.min(FILLING_STRING_CHAR_LEN);
            cs.queue_str(w, &self.filling_string[0..sl * self.char_size])?;
            len -= sl;
        }
        Ok(())
    }
}