17
17
use function Laravel \Prompts \confirm ;
18
18
use function Laravel \Prompts \multiselect ;
19
19
use function Laravel \Prompts \select ;
20
+ use function Laravel \Prompts \spin ;
20
21
use function Laravel \Prompts \text ;
21
22
22
23
class NewCommand extends Command
@@ -872,7 +873,7 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
872
873
}, $ commands );
873
874
}
874
875
875
- if ($ input -> getOption ( ' quiet ' )) {
876
+ if (! $ output -> isVerbose ( )) {
876
877
$ commands = array_map (function ($ value ) {
877
878
if (str_starts_with ($ value , 'chmod ' )) {
878
879
return $ value ;
@@ -886,7 +887,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
886
887
}, $ commands );
887
888
}
888
889
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 );
890
897
891
898
if ('\\' !== DIRECTORY_SEPARATOR && file_exists ('/dev/tty ' ) && is_readable ('/dev/tty ' )) {
892
899
try {
@@ -896,11 +903,13 @@ protected function runCommands($commands, InputInterface $input, OutputInterface
896
903
}
897
904
}
898
905
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 ) {
900
911
$ output ->write (' ' .$ line );
901
912
});
902
-
903
- return $ process ;
904
913
}
905
914
906
915
/**
@@ -951,4 +960,16 @@ protected function pregReplaceInFile(string $pattern, string $replace, string $f
951
960
preg_replace ($ pattern , $ replace , file_get_contents ($ file ))
952
961
);
953
962
}
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
+ }
954
975
}
0 commit comments