6
6
7
7
namespace door {
8
8
9
- BarLine::BarLine (const std::string &txt, int width)
10
- : Line(txt , width), barstyle{BarStyle::SOLID},
9
+ BarLine::BarLine (int width)
10
+ : Line(" " , width), barstyle{BarStyle::SOLID},
11
11
current_percent{0 }, length{width} {
12
12
init ();
13
13
}
14
14
15
- BarLine::BarLine (const char *txt, int width)
16
- : Line(txt, width), barstyle{BarStyle::SOLID},
17
- current_percent{0 }, length{width} {
18
- init ();
19
- }
20
-
21
- BarLine::BarLine (const std::string &txt, int width, ANSIColor c)
22
- : Line(txt, width, c), barstyle{BarStyle::SOLID},
23
- current_percent{0 }, length{width} {
15
+ BarLine::BarLine (int width, BarStyle style)
16
+ : Line(" " , width), barstyle{style}, current_percent{0 }, length{width} {
24
17
init ();
25
18
}
26
19
27
- BarLine::BarLine (const char *txt, int width, ANSIColor c)
28
- : Line(txt, width, c), barstyle{BarStyle::SOLID},
29
- current_percent{0 }, length{width} {
20
+ BarLine::BarLine (int width, BarStyle style, ANSIColor c)
21
+ : Line(" " , width, c), barstyle{style}, current_percent{0 }, length{width} {
30
22
init ();
31
23
}
32
24
@@ -53,6 +45,52 @@ void BarLine::init(void) {
53
45
update ();
54
46
}
55
47
48
+ void BarLine::watch (float &percent) {
49
+ door::updateFunction lineWatchUpdate = [this , &percent]() -> std::string {
50
+ this ->set (percent);
51
+ if (!colorRange.empty ()) {
52
+ // Ok, there is a range, so test for it.
53
+ ANSIColor ac;
54
+ // unsigned long p;
55
+ for (auto bc : colorRange) {
56
+ if (current_percent <= bc.percent ) {
57
+ ac = bc.c ;
58
+ // p = bc.percent;
59
+ break ;
60
+ };
61
+ }
62
+ // cout << "!" << current_percent << "," << p << " ";
63
+ setColor (ac);
64
+ }
65
+ return this ->update_bar ();
66
+ };
67
+ setUpdater (lineWatchUpdate);
68
+ update ();
69
+ }
70
+
71
+ void BarLine::watch (int &value, int &max) {
72
+ door::updateFunction lineWatchUpdate = [this , &value, &max]() -> std::string {
73
+ this ->set (value, max);
74
+ if (!colorRange.empty ()) {
75
+ // Ok, there is a range, so test for it.
76
+ ANSIColor ac;
77
+ // unsigned long p;
78
+ for (auto bc : colorRange) {
79
+ if (current_percent <= bc.percent ) {
80
+ ac = bc.c ;
81
+ // p = bc.percent;
82
+ break ;
83
+ };
84
+ }
85
+ // cout << "!" << current_percent << "," << p << " ";
86
+ setColor (ac);
87
+ }
88
+ return this ->update_bar ();
89
+ };
90
+ setUpdater (lineWatchUpdate);
91
+ update ();
92
+ }
93
+
56
94
void BarLine::setStyle (BarStyle s) { barstyle = s; }
57
95
void BarLine::set (int value, int max) {
58
96
unsigned long percentage = value * 100 * 100 / max;
0 commit comments