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