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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use crate::{BarCloseMethod, IsBar};
pub struct Spinni {
tick_strings: Vec<char>,
current_char: usize,
args: SpinniArgs,
job_name: String,
done: bool,
}
impl crate::isbar::IsBar for Spinni {
type Progress = String;
type Args = SpinniArgs;
fn new(job_name: String, args: Self::Args) -> Self
where
Self: Sized {
Self {
tick_strings: "⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈ "
.chars()
.collect(),
current_char: 0,
args,
job_name,
done: false,
}
}
fn done(&mut self) {
self.done = true;
}
fn is_done(&self) -> bool {
self.done
}
fn set_progress(&mut self, progress: Self::Progress) {
self.args.current_task_name = progress;
}
fn set_name(&mut self, job_name: String) {
self.job_name = job_name;
}
fn close_method(&self) -> crate::BarCloseMethod {
self.args.close_method
}
fn display(&mut self) -> String {
if self.current_char == self.tick_strings.len()-1 {
self.current_char = 0;
} else {
self.current_char += 1;
}
let spini_step = self.tick_strings[self.current_char];
format!("{} {}: {}", spini_step, self.job_name, self.args.current_task_name)
}
}
pub struct SpinniArgs {
current_task_name: String,
close_method: BarCloseMethod,
}
pub struct SpinniBuilder {
job_name: String,
task_name: String,
close_method: BarCloseMethod,
}
impl SpinniBuilder {
pub fn new(name: String) -> Self {
Self {
job_name: name,
task_name: "".into(),
close_method: BarCloseMethod::LeaveBehind,
}
}
pub fn task_name(mut self, task_name: String) -> Self {
self.task_name = task_name;
self
}
pub fn close_method(mut self, close_method: BarCloseMethod) -> Self {
self.close_method = close_method;
self
}
pub fn build(self) -> Spinni {
Spinni::new(self.job_name, SpinniArgs {current_task_name: self.task_name, close_method: self.close_method})
}
}