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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use fmt_iter::repeat;
use std::sync::atomic::{AtomicUsize, Ordering};
use zero_copy_pads::Width;
pub static GLOBAL_STATUS_BOARD: StatusBoard = StatusBoard::new();
#[derive(Debug)]
pub struct StatusBoard {
line_width: AtomicUsize,
}
impl StatusBoard {
const fn new() -> Self {
StatusBoard {
line_width: AtomicUsize::new(0),
}
}
fn get_line_width(&self) -> usize {
self.line_width.load(Ordering::Relaxed)
}
fn set_line_width(&self, value: usize) {
self.line_width.store(value, Ordering::Relaxed);
}
pub fn clear_line(&self, new_line_width: usize) {
let empty_line = repeat(' ', self.get_line_width());
eprint!("\r{}\r", empty_line);
self.set_line_width(new_line_width);
}
pub fn temporary_message(&self, message: &str) {
self.clear_line(message.width());
eprint!("{}", message);
}
pub fn permanent_message(&self, message: &str) {
self.clear_line(0);
eprintln!("{}", message);
}
}