Function kdam::term::width

source ·
pub fn width() -> Option<u16>
Expand description

Get terminal width.

Examples found in repository?
examples/showcase/spinner.rs (line 37)
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
fn main() {
    let spin = Spinner::new(
        &[
            "▁▂▃",
            "▂▃▄",
            "▃▄▅",
            "▄▅▆",
            "▅▆▇",
            "▆▇█",
            "▇█▇",
            "█▇▆",
            "▇▆▅",
            "▆▅▄",
            "▅▄▃",
            "▄▃▂",
            "▃▂▁",
        ],
        30.0,
        1.0,
    );

    let timer = Instant::now();

    loop {
        std::thread::sleep(Duration::from_secs_f32(0.02));
        Writer::Stderr
            .print_at(
                0,
                spin.render_frames(
                    timer.elapsed().as_secs_f32(),
                    NonZeroI16::new((term::width().unwrap_or(30) / 3) as i16).unwrap(),
                )
                .as_bytes(),
            )
            .unwrap();
    }
}