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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Monitor mode for progress bars.
//!
//! In monitor mode progress bar is refreshed in specific intervals.
//! Default monitor modes may not fit in many cases.
//! So, it is recommended to create a custom monitor mode.
//! The basic idea behind monitor mode is to create a separate thread for updating progress bar
//! which can be achieved by the following code.
//!
//! ```
//! use kdam::{Bar, BarExt};
//! use std::{
//! sync::{Arc, Mutex},
//! thread,
//! };
//!
//! fn custom_monitor(pb: Bar, maxinterval: f32) -> (Arc<Mutex<Bar>>, thread::JoinHandle<()>) {
//! let pb_arc = Arc::new(Mutex::new(pb));
//! let pb_arc_clone = pb_arc.clone();
//!
//! let handle = thread::spawn(move || loop {
//! thread::sleep(std::time::Duration::from_secs_f32(maxinterval));
//! let mut pb_monitor = pb_arc_clone.lock().unwrap();
//!
//! if pb_monitor.completed() {
//! break;
//! }
//!
//! let _ = pb_monitor.refresh();
//! });
//!
//! (pb_arc, handle)
//! }
//! ```
use crate;
use ;
/// Monitor mode for [Bar](crate::Bar).
///
/// # Example
///
/// ```no_run
/// use kdam::{tqdm, BarExt};
///
/// let pb = tqdm!(total = 100, force_refresh = true);
/// let (pb_arc, monitor_thread) = kdam::monitor::bar(pb, 1.0);
///
/// for _ in 0..100 {
/// pb_arc.lock().unwrap().update(1);
/// std::thread::sleep(std::time::Duration::from_secs_f32(3.0));
/// }
///
/// monitor_thread.join().unwrap();
/// eprintln!();
/// ```