18
18
use function Laravel \Prompts \confirm ;
19
19
use function Laravel \Prompts \multiselect ;
20
20
use function Laravel \Prompts \select ;
21
+ use function Laravel \Prompts \spin ;
21
22
use function Laravel \Prompts \text ;
22
23
23
24
class NewCommand extends Command
@@ -877,7 +878,7 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
877
878
}, $ commands );
878
879
}
879
880
880
- if ($ input -> getOption ( ' quiet ' )) {
881
+ if (! $ output -> isVerbose ( )) {
881
882
$ commands = array_map (function ($ value ) {
882
883
if (str_starts_with ($ value , 'chmod ' )) {
883
884
return $ value ;
@@ -891,7 +892,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
891
892
}, $ commands );
892
893
}
893
894
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 );
895
902
896
903
if ('\\' !== DIRECTORY_SEPARATOR && file_exists ('/dev/tty ' ) && is_readable ('/dev/tty ' )) {
897
904
try {
@@ -901,11 +908,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
901
908
}
902
909
}
903
910
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 ) {
905
916
$ output ->write (' ' .$ line );
906
917
});
907
-
908
- return $ process ;
909
918
}
910
919
911
920
/**
@@ -956,4 +965,16 @@ protected function pregReplaceInFile(string $pattern, string $replace, string $f
956
965
preg_replace ($ pattern , $ replace , file_get_contents ($ file ))
957
966
);
958
967
}
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
+ }
959
980
}
0 commit comments