1 | <?php |
||
13 | final class Spinner extends DynamicTerminalObject |
||
14 | { |
||
15 | /** |
||
16 | * @var string[] The characters to be used to present progress. |
||
17 | */ |
||
18 | private $characters = ["[=---]", "[-=--]", "[--=-]", "[---=]", "[--=-]", "[-=--]"]; |
||
19 | |||
20 | /** |
||
21 | * @var int The current item of the sequence |
||
22 | */ |
||
23 | private $current = 0; |
||
24 | |||
25 | /** |
||
26 | * @var bool Flag indicating whether we are writing the bar for the first time. |
||
27 | */ |
||
28 | private $firstLine = true; |
||
29 | |||
30 | /** |
||
31 | * @var string Current label. |
||
32 | */ |
||
33 | private $label; |
||
34 | |||
35 | /** |
||
36 | * @var float When the spinner was last drawn. |
||
37 | */ |
||
38 | private $lastDrawn; |
||
39 | |||
40 | /** |
||
41 | * @var float How long to wait in seconds between drawing each stage. |
||
42 | */ |
||
43 | private $timeLimit = 0.1; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * If they pass in a sequence, set the sequence |
||
48 | * |
||
49 | * @param string $label |
||
50 | * @param string ...$characters |
||
51 | */ |
||
52 | public function __construct($label = null, ...$characters) |
||
69 | |||
70 | |||
71 | /** |
||
72 | * Set the length of time to wait between drawing each stage. |
||
73 | * |
||
74 | * @param float $timeLimit |
||
75 | * |
||
76 | * @return Spinner |
||
77 | */ |
||
78 | public function timeLimit($timeLimit) |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Set the character to loop around. |
||
88 | * |
||
89 | * @param string $characters |
||
90 | * |
||
91 | * @return Spinner |
||
92 | */ |
||
93 | public function characters(...$characters) |
||
103 | |||
104 | |||
105 | /** |
||
106 | * Re-writes the spinner |
||
107 | * |
||
108 | * @param string $label |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public function advance($label = null) |
||
134 | |||
135 | |||
136 | /** |
||
137 | * Draw the spinner |
||
138 | * |
||
139 | * @param string $characters |
||
140 | * @param string $label |
||
141 | */ |
||
142 | private function drawSpinner($characters, $label) |
||
158 | } |
||
159 |