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
use tui::{
  style::{Color, Style, Modifier},
  widgets::{Block, Borders, Gauge},
  text::{Span},
};

use crate::fetch::fetch_stats::StatsResponse;

pub fn make_gauge(stats: &StatsResponse) -> Gauge {

  let total_blocked = stats.num_blocked_filtering
    + stats.num_replaced_parental
    + stats.num_replaced_safebrowsing
    + stats.num_replaced_safesearch;

  let percent = (total_blocked as f64 / stats.num_dns_queries as f64 * 100.0) as u16;

  let label = format!("Blocked {} out of {} ({}%)", total_blocked, stats.num_dns_queries, percent);

  Gauge::default()
      .block(
        Block::default()
        .title(Span::styled(
          "Block Percentage",
          Style::default().add_modifier(Modifier::BOLD),
        ))
        .borders(Borders::ALL)
    )
    .gauge_style(Style::default().fg(Color::Red).bg(Color::Green))
    .percent(percent)
    .label(label)
}