rcli_loader/
terminal_helper.rs

1use terminal_size::{Width, Height, terminal_size};
2
3// Coordinate 2d of u16
4pub struct V2Usz {
5    pub x: usize, pub y: usize
6} 
7
8pub fn get_terminal_size() -> V2Usz { //Result<V2Usz, &'static str> { - Temporarily disabled result returning to default a size instead
9    if let Some((Width(w), Height(h))) = terminal_size() {
10        return V2Usz { x: w as usize, y: h as usize};
11    } else {
12        //return Err("Unable to get terminal size");
13        return V2Usz {x:70, y:20};
14    }
15}
16
17pub fn get_line_count(count_str: &String) -> usize { // Line count is equal to both the newline characters, and the amount of wrapping lines (one "line" can wrap multiple times)
18    let ts: V2Usz = get_terminal_size();
19    let mut count: usize = 0;
20    count_str.lines().for_each(|line: &str| {
21        count += 1 + line.len() / ts.x as usize;
22    });
23    return count;
24}