Skip to content

Commit a123d0b

Browse files
committed
feat: enhance file copy confirmation with improved prompt handling
1 parent 49df7c8 commit a123d0b

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

src/Console/Command/Theme/CopyFromVendorCommand.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818

19+
use function Laravel\Prompts\confirm;
1920
use function Laravel\Prompts\search;
2021

2122
class CopyFromVendorCommand extends AbstractCommand
@@ -164,12 +165,32 @@ private function confirmCopy(string $sourceFile, string $absoluteDestPath, strin
164165
]);
165166
$this->io->newLine();
166167

167-
if (file_exists($absoluteDestPath)) {
168-
$this->io->warning("File already exists at destination!");
169-
return $this->io->confirm('Overwrite existing file?', false);
170-
}
168+
$this->setPromptEnvironment();
169+
170+
try {
171+
if (file_exists($absoluteDestPath)) {
172+
$this->io->warning("File already exists at destination!");
173+
$result = confirm(
174+
label: 'Overwrite existing file?',
175+
default: false
176+
);
177+
\Laravel\Prompts\Prompt::terminal()->restoreTty();
178+
$this->resetPromptEnvironment();
179+
return $result;
180+
}
171181

172-
return $this->io->confirm('Proceed with copy?', true);
182+
$result = confirm(
183+
label: 'Proceed with copy?',
184+
default: true
185+
);
186+
\Laravel\Prompts\Prompt::terminal()->restoreTty();
187+
$this->resetPromptEnvironment();
188+
return $result;
189+
} catch (\Exception $e) {
190+
$this->resetPromptEnvironment();
191+
$this->io->error('Interactive mode failed: ' . $e->getMessage());
192+
return false;
193+
}
173194
}
174195

175196
private function performCopy(string $absoluteSourcePath, string $absoluteDestPath): void
@@ -208,10 +229,6 @@ private function showDryRunPreview(string $sourceFile, string $absoluteDestPath,
208229

209230
private function fixPromptEnvironment(): void
210231
{
211-
if (getenv('DDEV_PROJECT')) {
212-
putenv('COLUMNS=100');
213-
putenv('LINES=40');
214-
putenv('TERM=xterm-256color');
215-
}
232+
$this->setPromptEnvironment();
216233
}
217234
}

0 commit comments

Comments
 (0)