@@ -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 ;
@@ -122,13 +128,25 @@ public function advance(): void
122
128
123
129
/**
124
130
* Finish the indicator with message.
131
+ *
132
+ * @param ?string $finishedIndicator
125
133
*/
126
- public function finish (string $ message ): void
134
+ public function finish (string $ message/* , ?string $finishedIndicator = null */ ): void
127
135
{
136
+ $ finishedIndicator = 1 < \func_num_args () ? func_get_arg (1 ) : null ;
137
+ if (null !== $ finishedIndicator && !\is_string ($ finishedIndicator )) {
138
+ throw new \TypeError (\sprintf ('Argument 2 passed to "%s()" must be of the type string or null, "%s" given. ' , __METHOD__ , get_debug_type ($ finishedIndicator )));
139
+ }
140
+
128
141
if (!$ this ->started ) {
129
142
throw new LogicException ('Progress indicator has not yet been started. ' );
130
143
}
131
144
145
+ if (null !== $ finishedIndicator ) {
146
+ $ this ->finishedIndicatorValue = $ finishedIndicator ;
147
+ }
148
+
149
+ $ this ->finished = true ;
132
150
$ this ->message = $ message ;
133
151
$ this ->display ();
134
152
$ this ->output ->writeln ('' );
@@ -215,7 +233,7 @@ private function getCurrentTimeInMilliseconds(): float
215
233
private static function initPlaceholderFormatters (): array
216
234
{
217
235
return [
218
- 'indicator ' => fn (self $ indicator ) => $ indicator ->indicatorValues [$ indicator ->indicatorCurrent % \count ($ indicator ->indicatorValues )],
236
+ 'indicator ' => fn (self $ indicator ) => $ indicator ->finished ? $ indicator -> finishedIndicatorValue : $ indicator -> indicatorValues [$ indicator ->indicatorCurrent % \count ($ indicator ->indicatorValues )],
219
237
'message ' => fn (self $ indicator ) => $ indicator ->message ,
220
238
'elapsed ' => fn (self $ indicator ) => Helper::formatTime (time () - $ indicator ->startTime , 2 ),
221
239
'memory ' => fn () => Helper::formatMemory (memory_get_usage (true )),
0 commit comments