@@ -36,8 +36,10 @@ class ProgressIndicator
36
36
private ?string $ message = null ;
37
37
private array $ indicatorValues ;
38
38
private int $ indicatorCurrent ;
39
+ private string $ finishedIndicatorValue ;
39
40
private float $ indicatorUpdateTime ;
40
41
private bool $ started = false ;
42
+ private bool $ finished = false ;
41
43
42
44
/**
43
45
* @var array<string, callable>
@@ -53,17 +55,20 @@ public function __construct(
53
55
?string $ format = null ,
54
56
private int $ indicatorChangeInterval = 100 ,
55
57
?array $ indicatorValues = null ,
58
+ ?string $ finishedIndicatorValue = null ,
56
59
) {
57
60
$ format ??= $ this ->determineBestFormat ();
58
61
$ indicatorValues ??= ['- ' , '\\' , '| ' , '/ ' ];
59
62
$ indicatorValues = array_values ($ indicatorValues );
63
+ $ finishedIndicatorValue ??= '✔ ' ;
60
64
61
65
if (2 > \count ($ indicatorValues )) {
62
66
throw new InvalidArgumentException ('Must have at least 2 indicator value characters. ' );
63
67
}
64
68
65
69
$ this ->format = self ::getFormatDefinition ($ format );
66
70
$ this ->indicatorValues = $ indicatorValues ;
71
+ $ this ->finishedIndicatorValue = $ finishedIndicatorValue ;
67
72
$ this ->startTime = time ();
68
73
}
69
74
@@ -88,6 +93,7 @@ public function start(string $message): void
88
93
89
94
$ this ->message = $ message ;
90
95
$ this ->started = true ;
96
+ $ this ->finished = false ;
91
97
$ this ->startTime = time ();
92
98
$ this ->indicatorUpdateTime = $ this ->getCurrentTimeInMilliseconds () + $ this ->indicatorChangeInterval ;
93
99
$ this ->indicatorCurrent = 0 ;
@@ -123,12 +129,17 @@ public function advance(): void
123
129
/**
124
130
* Finish the indicator with message.
125
131
*/
126
- public function finish (string $ message ): void
132
+ public function finish (string $ message, ? string $ finishedIndicator = null ): void
127
133
{
128
134
if (!$ this ->started ) {
129
135
throw new LogicException ('Progress indicator has not yet been started. ' );
130
136
}
131
137
138
+ if ($ finishedIndicator !== null ) {
139
+ $ this ->finishedIndicatorValue = $ finishedIndicator ;
140
+ }
141
+
142
+ $ this ->finished = true ;
132
143
$ this ->message = $ message ;
133
144
$ this ->display ();
134
145
$ this ->output ->writeln ('' );
@@ -215,7 +226,7 @@ private function getCurrentTimeInMilliseconds(): float
215
226
private static function initPlaceholderFormatters (): array
216
227
{
217
228
return [
218
- 'indicator ' => fn (self $ indicator ) => $ indicator ->indicatorValues [$ indicator ->indicatorCurrent % \count ($ indicator ->indicatorValues )],
229
+ 'indicator ' => fn (self $ indicator ) => $ indicator ->finished ? $ indicator -> finishedIndicatorValue : $ indicator -> indicatorValues [$ indicator ->indicatorCurrent % \count ($ indicator ->indicatorValues )],
219
230
'message ' => fn (self $ indicator ) => $ indicator ->message ,
220
231
'elapsed ' => fn (self $ indicator ) => Helper::formatTime (time () - $ indicator ->startTime , 2 ),
221
232
'memory ' => fn () => Helper::formatMemory (memory_get_usage (true )),
0 commit comments