@@ -17,9 +17,10 @@ class CnKill extends Command
1717 * @var string
1818 */
1919 protected $ signature = 'process {path? : The path to search for vendor directories}
20- {--maxdepth= : The maximum depth to search for vendor directories}
21- {--node : Search for node_modules directories instead of vendor}
22- {--all : Search for both vendor and node_modules directories} ' ;
20+ {--maxdepth= : The maximum depth to search for vendor directories}
21+ {--node : Search for node_modules directories instead of vendor}
22+ {--all : Search for both vendor and node_modules directories}
23+ {--sort=default : Sort by default, name, size, or modified} ' ;
2324
2425 /**
2526 * The console command description.
@@ -38,7 +39,7 @@ class CnKill extends Command
3839 * 'deleting' — rm -rf in progress
3940 * 'deleted' — rm -rf completed
4041 *
41- * @var array<string, array{project: string, size: int|null, status: string, type: string, lastModified: int|null}>
42+ * @var array<string, array{project: string, size: int|null, status: string, type: string, lastModified: int|null, order: int }>
4243 */
4344 protected array $ state = [];
4445
@@ -129,6 +130,10 @@ public function handle(): int
129130 return 1 ;
130131 }
131132
133+ if (! $ this ->initializeSortMode ()) {
134+ return 1 ;
135+ }
136+
132137 // Resolve package-manager cache dirs to exclude from scanning
133138 $ this ->excludePaths = $ this ->resolveExcludePaths ();
134139
@@ -386,13 +391,15 @@ protected function registerDir(string $dir): void
386391 return ;
387392 }
388393
394+ $ order = count ($ this ->dirs );
389395 $ this ->dirs [] = $ dir ;
390396 $ this ->state [$ dir ] = [
391397 'project ' => basename ($ parent ),
392398 'size ' => null ,
393399 'status ' => 'calculating ' ,
394400 'type ' => $ type ,
395401 'lastModified ' => $ this ->resolveLastModified ($ parent , $ dir , $ type ),
402+ 'order ' => $ order ,
396403 ];
397404
398405 $ this ->enqueueSizeProcess ($ dir );
@@ -458,18 +465,10 @@ protected function resolveLastModified(string $projectPath, string $dir, string
458465
459466 protected function writeListLines (): void
460467 {
461- $ count = count ($ this ->dirs );
468+ $ visibleDirs = $ this ->syncCursorState ($ this ->visibleDirs ());
469+ $ count = count ($ visibleDirs );
462470 [$ totalSize , $ allSized , $ deletedCount , $ freedSize ] = $ this ->computeStats ();
463471
464- // Clamp cursor / offset to current list length
465- if ($ count > 0 && $ this ->cursor >= $ count ) {
466- $ this ->cursor = $ count - 1 ;
467- }
468-
469- if ($ this ->scrollOffset > max (0 , $ count - $ this ->visibleRows )) {
470- $ this ->scrollOffset = max (0 , $ count - $ this ->visibleRows );
471- }
472-
473472 $ visibleEnd = min ($ this ->scrollOffset + $ this ->visibleRows , $ count );
474473
475474 // Empty state while searching — hidden once done (status bar shows "done")
@@ -482,7 +481,7 @@ protected function writeListLines(): void
482481 $ numWidth = mb_strlen ((string ) $ count );
483482
484483 for ($ i = $ this ->scrollOffset ; $ i < $ visibleEnd ; $ i ++) {
485- $ dir = $ this -> dirs [$ i ];
484+ $ dir = $ visibleDirs [$ i ];
486485 $ info = $ this ->state [$ dir ];
487486 $ isActive = ($ i === $ this ->cursor );
488487
0 commit comments