1use crate::config::Config;
2
3pub fn render_bar(value: f64, max: f64, width: usize, config: &Config) -> String {
4 let (filled_char, empty_char) = config.bar_chars();
5 let ratio = (value / max).clamp(0.0, 1.0);
6 let filled = (ratio * width as f64) as usize;
7 let empty = width - filled;
8
9 format!(
10 "{}{}",
11 std::iter::repeat_n(filled_char, filled).collect::<String>(),
12 std::iter::repeat_n(empty_char, empty).collect::<String>()
13 )
14}
15
16pub fn render_percentage_bar(percentage: f64, width: usize, config: &Config) -> String {
17 render_bar(percentage, 100.0, width, config)
18}