|
5 | 5 | namespace App\Commands; |
6 | 6 |
|
7 | 7 | use App\Services\ConfigService; |
| 8 | +use Laravel\Prompts\ConfirmPrompt; |
| 9 | +use Laravel\Prompts\MultiSelectPrompt; |
| 10 | +use Laravel\Prompts\SelectPrompt; |
8 | 11 | use LaravelZero\Framework\Commands\Command; |
9 | 12 |
|
10 | | -use function Laravel\Prompts\confirm; |
11 | | -use function Laravel\Prompts\multiselect; |
12 | | -use function Laravel\Prompts\select; |
13 | 13 | use function Laravel\Prompts\text; |
14 | 14 |
|
15 | 15 | class ConfigCommand extends Command |
@@ -63,16 +63,18 @@ private function handleList(ConfigService $config): int |
63 | 63 |
|
64 | 64 | $this->newLine(); |
65 | 65 | $this->line(' <options=bold>cnkill config</> — select which folder types to scan.'); |
66 | | - $this->line(' <fg=gray>Use <space> to toggle, <enter> to save. Run `cnkill config add` to add custom types.</>'); |
| 66 | + $this->line(' <fg=gray>Use <space> to toggle, <enter> to save, <q> to quit. Run `cnkill config add` to add custom types.</>'); |
67 | 67 | $this->newLine(); |
68 | 68 |
|
69 | | - $selected = multiselect( |
| 69 | + $prompt = new MultiSelectPrompt( |
70 | 70 | label: 'Enabled folder types', |
71 | 71 | options: $options, |
72 | 72 | default: $currentlyEnabled, |
73 | 73 | scroll: min(count($options), 20), |
74 | 74 | hint: 'Changes take effect immediately for all future scans.', |
75 | 75 | ); |
| 76 | + $prompt->on('key', fn (string $key) => $key === 'q' ? exit(0) : null); |
| 77 | + $selected = $prompt->prompt(); |
76 | 78 |
|
77 | 79 | if (! is_array($selected)) { |
78 | 80 | $this->newLine(); |
@@ -116,7 +118,7 @@ private function handleAdd(ConfigService $config): int |
116 | 118 |
|
117 | 119 | $this->newLine(); |
118 | 120 | $this->line(' <options=bold>cnkill config add</> — define a custom folder type to scan.'); |
119 | | - $this->line(' <fg=gray>Press Ctrl-C at any time to cancel.</>'); |
| 121 | + $this->line(' <fg=gray>Press <q> or Ctrl-C at any time to cancel.</>'); |
120 | 122 | $this->newLine(); |
121 | 123 |
|
122 | 124 | // ── 1. Folder name / pattern ───────────────────────────────────────── |
@@ -206,7 +208,9 @@ private function handleAdd(ConfigService $config): int |
206 | 208 | $this->line(sprintf(' Lockfiles: <fg=gray>%s</>', $lockfiles ? implode(', ', $lockfiles) : 'none')); |
207 | 209 | $this->newLine(); |
208 | 210 |
|
209 | | - $confirmed = confirm(label: 'Save this custom type?', default: true); |
| 211 | + $confirmPrompt = new ConfirmPrompt(label: 'Save this custom type?', default: true); |
| 212 | + $confirmPrompt->on('key', fn (string $k) => $k === 'q' ? exit(0) : null); |
| 213 | + $confirmed = $confirmPrompt->prompt(); |
210 | 214 |
|
211 | 215 | if (! $confirmed) { |
212 | 216 | $this->newLine(); |
@@ -265,20 +269,24 @@ private function handleRemove(ConfigService $config): int |
265 | 269 | $options[$key] = $type['label']; |
266 | 270 | } |
267 | 271 |
|
268 | | - $key = select( |
| 272 | + $selectPrompt = new SelectPrompt( |
269 | 273 | label: 'Which custom type do you want to remove?', |
270 | 274 | options: $options, |
271 | 275 | scroll: min(count($options), 15), |
272 | 276 | ); |
| 277 | + $selectPrompt->on('key', fn (string $k) => $k === 'q' ? exit(0) : null); |
| 278 | + $key = $selectPrompt->prompt(); |
273 | 279 |
|
274 | 280 | $typeLabel = $customTypes[(string) $key]['label'] ?? (string) $key; |
275 | 281 |
|
276 | 282 | $this->newLine(); |
277 | | - $confirmed = confirm( |
| 283 | + $confirmPrompt = new ConfirmPrompt( |
278 | 284 | label: "Remove \"{$typeLabel}\"?", |
279 | 285 | default: false, |
280 | 286 | hint: 'This cannot be undone.', |
281 | 287 | ); |
| 288 | + $confirmPrompt->on('key', fn (string $k) => $k === 'q' ? exit(0) : null); |
| 289 | + $confirmed = $confirmPrompt->prompt(); |
282 | 290 |
|
283 | 291 | if (! $confirmed) { |
284 | 292 | $this->newLine(); |
|
0 commit comments