@@ -11,7 +11,7 @@ import {
1111} from '../constants/index.js' ;
1212import { ERROR_MSG , INFO_MSGS } from '../constants/messages.constants.js' ;
1313import { IConfig , CliScanFoundFolder , IKeyPress } from './interfaces/index.js' ;
14- import { firstValueFrom , Observable } from 'rxjs' ;
14+ import { firstValueFrom , Observable , Subject } from 'rxjs' ;
1515import { filter , map , mergeMap , switchMap , tap } from 'rxjs/operators' ;
1616
1717import { COLORS } from '../constants/cli.constants.js' ;
@@ -46,7 +46,6 @@ import { getFileContent } from '../utils/get-file-content.js';
4646import { ResultDetailsUi } from './ui/components/result-details.ui.js' ;
4747
4848export class CliController {
49- private folderRoot = '' ;
5049 private readonly stdout : NodeJS . WriteStream = process . stdout ;
5150 private readonly config : IConfig = DEFAULT_CONFIG ;
5251
@@ -113,7 +112,7 @@ export class CliController {
113112 }
114113
115114 private initUi ( ) : void {
116- this . uiHeader = new HeaderUi ( ) ;
115+ this . uiHeader = new HeaderUi ( this . config ) ;
117116 this . uiService . add ( this . uiHeader ) ;
118117 this . uiResults = new ResultsUi ( this . resultsService , this . consoleService ) ;
119118 this . uiService . add ( this . uiResults ) ;
@@ -144,14 +143,32 @@ export class CliController {
144143 }
145144
146145 private openOptions ( ) : void {
147- const optionsUi = new OptionsUi ( ) ;
146+ const changeConfig$ = new Subject < Partial < IConfig > > ( ) ;
147+ const optionsUi = new OptionsUi ( changeConfig$ , this . config ) ;
148148 this . uiResults . clear ( ) ;
149149 this . uiResults . setVisible ( false ) ;
150150 this . uiService . add ( optionsUi ) ;
151151 this . activeComponent = optionsUi ;
152152 this . uiHeader . menuIndex$ . next ( MENU_BAR_OPTIONS . OPTIONS ) ;
153153 this . uiService . renderAll ( ) ;
154154
155+ changeConfig$ . subscribe ( ( configChanges ) => {
156+ Object . assign ( this . config , configChanges ) ;
157+ if (
158+ configChanges . targetFolder ||
159+ configChanges . folderRoot ||
160+ configChanges . excludeHiddenDirectories ||
161+ configChanges . exclude
162+ ) {
163+ this . scan ( ) ;
164+ }
165+ if ( configChanges . sortBy ) {
166+ this . resultsService . sortResults ( configChanges . sortBy ) ;
167+ }
168+ this . logger . info ( `Config updated: ${ JSON . stringify ( configChanges ) } ` ) ;
169+ this . uiService . renderAll ( ) ;
170+ } ) ;
171+
155172 optionsUi . goToHelp$ . subscribe ( ( ) => {
156173 const helpUi = new HelpUi ( ) ;
157174 this . uiService . add ( helpUi ) ;
@@ -240,11 +257,11 @@ export class CliController {
240257 this . config . exclude = [ ...this . config . exclude , ...userExcludeList ] ;
241258 }
242259
243- this . folderRoot = options . isTrue ( 'directory' )
260+ this . config . folderRoot = options . isTrue ( 'directory' )
244261 ? options . getString ( 'directory' )
245262 : process . cwd ( ) ;
246263 if ( options . isTrue ( 'full-scan' ) ) {
247- this . folderRoot = homedir ( ) ;
264+ this . config . folderRoot = homedir ( ) ;
248265 }
249266 if ( options . isTrue ( 'hide-errors' ) ) {
250267 this . config . showErrors = false ;
@@ -267,15 +284,14 @@ export class CliController {
267284
268285 if ( options . isTrue ( 'dry-run' ) ) {
269286 this . config . dryRun = true ;
270- this . uiHeader . isDryRun = true ;
271287 }
272288
273289 if ( options . isTrue ( 'yes' ) ) {
274290 this . config . yes = true ;
275291 }
276292
277293 // Remove trailing slash from folderRoot for consistency
278- this . folderRoot = this . folderRoot . replace ( / [ / \\ ] $ / , '' ) ;
294+ this . config . folderRoot = this . config . folderRoot . replace ( / [ / \\ ] $ / , '' ) ;
279295 }
280296
281297 private showErrorPopup ( visible : boolean ) : void {
@@ -356,7 +372,7 @@ export class CliController {
356372 }
357373
358374 private checkFileRequirements ( ) : void {
359- const result = this . npkill . isValidRootFolder ( this . folderRoot ) ;
375+ const result = this . npkill . isValidRootFolder ( this . config . folderRoot ) ;
360376 if ( ! result . isValid ) {
361377 const errorMessage =
362378 result . invalidReason || 'Root folder is not valid. Unknown reason' ;
@@ -437,6 +453,9 @@ export class CliController {
437453 }
438454
439455 private scan ( ) : void {
456+ this . searchStatus . reset ( ) ;
457+ this . resultsService . reset ( ) ;
458+ this . uiStatus . reset ( ) ;
440459 this . uiStatus . start ( ) ;
441460
442461 const params = this . prepareListDirParams ( ) ;
@@ -495,7 +514,7 @@ export class CliController {
495514 private prepareListDirParams ( ) {
496515 const target = this . config . targetFolder ;
497516 const params = {
498- rootPath : this . folderRoot ,
517+ rootPath : this . config . folderRoot ,
499518 targets : [ target ] ,
500519 } ;
501520
0 commit comments