@@ -64,12 +64,8 @@ protected function configure()
64
64
*/
65
65
protected function execute (InputInterface $ input , OutputInterface $ output ): int
66
66
{
67
- $ xml = ($ input ->getOption ('xml ' ))
68
- ? '--xml '
69
- : "" ;
70
- $ noAnsi = ($ input ->getOption ('no-ansi ' ))
71
- ? '--no-ansi '
72
- : "" ;
67
+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
68
+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
73
69
$ skipGeneration = $ input ->getOption ('skip-generate ' );
74
70
$ force = $ input ->getOption ('force ' );
75
71
$ groups = $ input ->getArgument ('groups ' );
@@ -140,11 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
140
136
$ process ->setTimeout (0 );
141
137
$ returnCodes [] = $ process ->run (
142
138
function ($ type , $ buffer ) use ($ output , $ noAnsi ) {
143
- if ($ noAnsi != "" ) {
144
- $ pattern = "/ \x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/ " ;
145
- // Use preg_replace to remove ANSI escape codes from the string
146
- $ buffer = preg_replace ($ pattern , '' , $ buffer );
147
- }
139
+ $ buffer = $ this ->disableAnsiColorCodes ($ buffer , $ noAnsi );
148
140
$ output ->write ($ buffer );
149
141
}
150
142
);
@@ -167,4 +159,19 @@ function ($type, $buffer) use ($output, $noAnsi) {
167
159
}
168
160
return max ($ exitCode , $ generationErrorCode );
169
161
}
162
+
163
+ /**
164
+ * @param string $buffer
165
+ * @param string $noAnsi
166
+ * @return string
167
+ */
168
+ private function disableAnsiColorCodes ($ buffer , $ noAnsi ) :string
169
+ {
170
+ if (empty ($ noAnsi )) {
171
+ return $ buffer ;
172
+ }
173
+ $ pattern = "/ \x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/ " ;
174
+ // Use preg_replace to remove ANSI escape codes from the string
175
+ return preg_replace ($ pattern , '' , $ buffer );
176
+ }
170
177
}
0 commit comments