parallel_disk_usage/
status_board.rs1use fmt_iter::repeat;
2use std::sync::atomic::{AtomicUsize, Ordering};
3use zero_copy_pads::Width;
4
5pub static GLOBAL_STATUS_BOARD: StatusBoard = StatusBoard::new();
7
8#[derive(Debug)]
10pub struct StatusBoard {
11 line_width: AtomicUsize,
12}
13
14impl StatusBoard {
15 const fn new() -> Self {
17 StatusBoard {
18 line_width: AtomicUsize::new(0),
19 }
20 }
21
22 fn get_line_width(&self) -> usize {
24 self.line_width.load(Ordering::Relaxed)
25 }
26
27 fn set_line_width(&self, value: usize) {
29 self.line_width.store(value, Ordering::Relaxed);
30 }
31
32 pub fn clear_line(&self, new_line_width: usize) {
34 let empty_line = repeat(' ', self.get_line_width());
35 eprint!("\r{empty_line}\r");
36 self.set_line_width(new_line_width);
37 }
38
39 pub fn temporary_message(&self, message: &str) {
41 self.clear_line(message.width());
42 eprint!("{message}");
43 }
44
45 pub fn permanent_message(&self, message: &str) {
47 self.clear_line(0);
48 eprintln!("{message}");
49 }
50}