1717use function Laravel \Prompts \confirm ;
1818use function Laravel \Prompts \multiselect ;
1919use function Laravel \Prompts \select ;
20+ use function Laravel \Prompts \spin ;
2021use function Laravel \Prompts \text ;
2122
2223class NewCommand extends Command
@@ -872,7 +873,7 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
872873 }, $ commands );
873874 }
874875
875- if ($ input -> getOption ( ' quiet ' )) {
876+ if (! $ output -> isVerbose ( )) {
876877 $ commands = array_map (function ($ value ) {
877878 if (str_starts_with ($ value , 'chmod ' )) {
878879 return $ value ;
@@ -886,7 +887,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
886887 }, $ commands );
887888 }
888889
889- $ process = Process::fromShellCommandline (implode (' && ' , $ commands ), $ workingPath , $ env , null , null );
890+ $ commands = implode (' && ' , $ commands );
891+
892+ if ($ this ->canUseSpinner ($ input , $ output )) {
893+ $ commands .= ' > /dev/null 2>&1 ' ;
894+ }
895+
896+ $ process = Process::fromShellCommandline ($ commands , $ workingPath , $ env , null , null );
890897
891898 if ('\\' !== DIRECTORY_SEPARATOR && file_exists ('/dev/tty ' ) && is_readable ('/dev/tty ' )) {
892899 try {
@@ -896,11 +903,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
896903 }
897904 }
898905
899- $ process ->run (function ($ type , $ line ) use ($ output ) {
906+ if ($ this ->canUseSpinner ($ input , $ output )) {
907+ return spin (fn () => tap ($ process )->run (), 'Installing... ' );
908+ }
909+
910+ return tap ($ process )->run (function ($ type , $ line ) use ($ output ) {
900911 $ output ->write (' ' .$ line );
901912 });
902-
903- return $ process ;
904913 }
905914
906915 /**
@@ -951,4 +960,16 @@ protected function pregReplaceInFile(string $pattern, string $replace, string $f
951960 preg_replace ($ pattern , $ replace , file_get_contents ($ file ))
952961 );
953962 }
963+
964+ /**
965+ * Checks if its possible to use the spinner.
966+ *
967+ * @return bool
968+ */
969+ protected function canUseSpinner (InputInterface $ input , OutputInterface $ output )
970+ {
971+ return function_exists ('pcntl_fork ' ) &&
972+ ! $ output ->isVerbose () &&
973+ ! $ input ->getOption ('quiet ' );
974+ }
954975}
0 commit comments