rcli_loader/
drawer_helper.rs1use crate::{loading_element::LoadingElement, terminal_helper::V2Usz};
2pub enum Position {
3 TOP,BOTTOM
4}
5
6pub trait LoadingColorScheme {
7 fn get_char_block_color(&self, l_elem: &LoadingElement) -> Box<str>; }
9
10pub struct RedGreenScheme {}
11impl LoadingColorScheme for RedGreenScheme {
12 fn get_char_block_color(&self, l_elem: &LoadingElement) -> Box<str> {
13 let ratio = if l_elem.get_max() > 0 {255 * l_elem.get_progress() / l_elem.get_max()} else {0}; return Box::from(format!("\x1b[38;2;{r};{g};{b}m", r=255-ratio, g=ratio, b=0)) }
16}
17
18pub struct BlueScheme {}
19impl LoadingColorScheme for BlueScheme {
20 fn get_char_block_color(&self, _l_elem: &LoadingElement) -> Box<str> {
21 Box::from(format!("\x1b[38;2;{r};{g};{b}m", r=0, g=0, b=255)) }
23}
24
25pub fn set_terminal_pos(pos: V2Usz) {
27 print!("\x1B[{line};{column}H", column = pos.x as usize, line = pos.y as usize);
28}
29
30pub fn print_splitter_line(terminal_size: &V2Usz, offset_height: usize) {
33 set_terminal_pos(V2Usz { x: 0, y: offset_height }); print!("{end:\u{2500}>times$}", end="", times=terminal_size.x as usize); }
36
37