1818use function Laravel \Prompts \confirm ;
1919use function Laravel \Prompts \multiselect ;
2020use function Laravel \Prompts \select ;
21+ use function Laravel \Prompts \spin ;
2122use function Laravel \Prompts \text ;
2223
2324class NewCommand extends Command
@@ -877,7 +878,7 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
877878 }, $ commands );
878879 }
879880
880- if ($ input -> getOption ( ' quiet ' )) {
881+ if (! $ output -> isVerbose ( )) {
881882 $ commands = array_map (function ($ value ) {
882883 if (str_starts_with ($ value , 'chmod ' )) {
883884 return $ value ;
@@ -891,7 +892,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
891892 }, $ commands );
892893 }
893894
894- $ process = Process::fromShellCommandline (implode (' && ' , $ commands ), $ workingPath , $ env , null , null );
895+ $ commands = implode (' && ' , $ commands );
896+
897+ if ($ this ->canUseSpinner ($ input , $ output )) {
898+ $ commands .= ' > /dev/null 2>&1 ' ;
899+ }
900+
901+ $ process = Process::fromShellCommandline ($ commands , $ workingPath , $ env , null , null );
895902
896903 if ('\\' !== DIRECTORY_SEPARATOR && file_exists ('/dev/tty ' ) && is_readable ('/dev/tty ' )) {
897904 try {
@@ -901,11 +908,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
901908 }
902909 }
903910
904- $ process ->run (function ($ type , $ line ) use ($ output ) {
911+ if ($ this ->canUseSpinner ($ input , $ output )) {
912+ return spin (fn () => tap ($ process )->run (), 'Installing... ' );
913+ }
914+
915+ return tap ($ process )->run (function ($ type , $ line ) use ($ output ) {
905916 $ output ->write (' ' .$ line );
906917 });
907-
908- return $ process ;
909918 }
910919
911920 /**
@@ -956,4 +965,16 @@ protected function pregReplaceInFile(string $pattern, string $replace, string $f
956965 preg_replace ($ pattern , $ replace , file_get_contents ($ file ))
957966 );
958967 }
968+
969+ /**
970+ * Checks if its possible to use the spinner.
971+ *
972+ * @return bool
973+ */
974+ protected function canUseSpinner (InputInterface $ input , OutputInterface $ output )
975+ {
976+ return function_exists ('pcntl_fork ' ) &&
977+ ! $ output ->isVerbose () &&
978+ ! $ input ->getOption ('quiet ' );
979+ }
959980}
0 commit comments