55use Illuminate \Console \Command ;
66use Illuminate \Filesystem \Filesystem ;
77use Symfony \Component \Finder \Finder ;
8- use function Laravel \Prompts \select ;
98use function Laravel \Prompts \confirm ;
109use function Laravel \Prompts \info ;
10+ use function Laravel \Prompts \search ;
11+ use function Laravel \Prompts \select ;
1112
1213class PublishViewCommand extends Command
1314{
@@ -23,7 +24,7 @@ public function handle()
2324 $ targetBase = resource_path ('views/vendor/forms ' );
2425 $ filesystem = new Filesystem ();
2526
26- if (! $ filesystem ->isDirectory ($ sourcePath )) {
27+ if (!$ filesystem ->isDirectory ($ sourcePath )) {
2728 $ this ->error ('Source view directory not found. ' );
2829 return 1 ;
2930 }
@@ -75,7 +76,7 @@ protected function getViewFiles(string $sourcePath, Filesystem $filesystem): arr
7576 foreach ($ tempFiles as $ relativePath => $ realPath ) {
7677 $ files [$ count ] = [
7778 'relative_path ' => $ relativePath ,
78- 'real_path ' => $ realPath ,
79+ 'real_path ' => $ realPath ,
7980 ];
8081 $ count ++;
8182 }
@@ -101,7 +102,7 @@ protected function promptForFileSelection(array $files, string $targetBase, File
101102 $ relative = $ file ['relative_path ' ];
102103
103104 $ targetPath = $ targetBase . DIRECTORY_SEPARATOR . str_replace ('/ ' , DIRECTORY_SEPARATOR , $ relative );
104- $ exists = $ filesystem ->exists ($ targetPath );
105+ $ exists = $ filesystem ->exists ($ targetPath );
105106
106107 $ status = $ exists
107108 ? '<fg=yellow>Published</> '
@@ -115,20 +116,31 @@ protected function promptForFileSelection(array $files, string $targetBase, File
115116 $ this ->newLine ();
116117
117118 // returns the KEY we defined (relative path)
118- $ selectedRelativePath = select (
119- label: 'Which view would you like to publish? ' ,
120- options: $ options ,
121- );
122-
123- $ selected_file = $ this ->parseChoice ($ selectedRelativePath );
119+ $ choice = windows_os ()
120+ ? select (
121+ label: 'Which view would you like to publish? ' ,
122+ options: $ options ,
123+ scroll: 15
124+ )
125+ : search (
126+ label: 'Which view would you like to publish? ' ,
127+ options: fn ($ search ) => array_values (array_filter (
128+ $ options ,
129+ fn ($ choice ) => str_contains (strtolower ($ choice ), strtolower ($ search ))
130+ )),
131+ placeholder: 'Search... ' ,
132+ scroll: 15
133+ );
134+
135+ $ selected_file = $ this ->parseChoice ($ choice );
124136
125137 // Find the index in the $files array
126138 $ selectedIndex = array_search ($ selected_file , array_column ($ files , 'relative_path ' ), true );
127139
128140 return $ selectedIndex !== false ? $ selectedIndex : null ;
129141 }
130142
131- public function parseChoice (string $ choice )
143+ public function parseChoice (string $ choice ): string
132144 {
133145 [$ type , $ value ] = explode (': ' , strip_tags ($ choice ));
134146
@@ -142,7 +154,7 @@ protected function publishFiles(array $selected, array $files, string $targetBas
142154 $ overwritten = 0 ;
143155
144156 foreach ($ selected as $ fileIndex ) {
145- if (! isset ($ files [$ fileIndex ])) {
157+ if (!isset ($ files [$ fileIndex ])) {
146158 continue ;
147159 }
148160
@@ -155,15 +167,15 @@ protected function publishFiles(array $selected, array $files, string $targetBas
155167
156168 $ exists = $ filesystem ->exists ($ targetPath );
157169
158- if ($ exists && ! $ this ->option ('force ' )) {
170+ if ($ exists && !$ this ->option ('force ' )) {
159171 $ shouldOverwrite = confirm (
160172 label: "File {$ relativePath } already exists. Overwrite? " ,
161173 default: false ,
162174 yes: 'Yes, overwrite ' ,
163175 no: 'No, skip '
164176 );
165177
166- if (! $ shouldOverwrite ) {
178+ if (!$ shouldOverwrite ) {
167179 $ this ->line (" <fg=yellow>SKIPPED</> {$ relativePath }" );
168180 $ skipped ++;
169181 continue ;
0 commit comments