@@ -13,7 +13,7 @@ mod container_state;
13
13
use crate :: {
14
14
app_error:: AppError ,
15
15
config:: Config ,
16
- ui:: { log_sanitizer, GuiState , Status } ,
16
+ ui:: { log_sanitizer, GuiState , Redraw , Status } ,
17
17
ENTRY_POINT ,
18
18
} ;
19
19
pub use container_state:: * ;
@@ -122,7 +122,9 @@ pub struct AppData {
122
122
error : Option < AppError > ,
123
123
filter : Filter ,
124
124
hidden_containers : Vec < ContainerItem > ,
125
+ redraw : Arc < Redraw > ,
125
126
sorted_by : Option < ( Header , SortedOrder ) > ,
127
+ current_sorted_id : Vec < ContainerId > ,
126
128
pub config : Config ,
127
129
}
128
130
@@ -134,18 +136,22 @@ pub struct AppData {
134
136
pub error : Option < AppError > ,
135
137
pub filter : Filter ,
136
138
pub hidden_containers : Vec < ContainerItem > ,
139
+ pub current_sorted_id : Vec < ContainerId > ,
140
+ pub redraw : Arc < Redraw > ,
137
141
pub sorted_by : Option < ( Header , SortedOrder ) > ,
138
142
}
139
143
140
144
impl AppData {
141
145
/// Generate a default app_state
142
- pub fn default ( config : Config ) -> Self {
146
+ pub fn new ( config : Config , redraw : & Arc < Redraw > ) -> Self {
143
147
Self {
144
148
config,
145
149
containers : StatefulList :: new ( vec ! [ ] ) ,
150
+ current_sorted_id : vec ! [ ] ,
146
151
error : None ,
147
152
filter : Filter :: new ( ) ,
148
153
hidden_containers : vec ! [ ] ,
154
+ redraw : Arc :: clone ( redraw) ,
149
155
sorted_by : None ,
150
156
}
151
157
}
@@ -186,6 +192,7 @@ impl AppData {
186
192
/// sets the state to start if any filtering has occurred
187
193
/// Also search in the "hidden" vec for items and insert back into the main containers vec
188
194
fn filter_containers ( & mut self ) {
195
+ self . redraw . set_true ( ) ;
189
196
let pre_len = self . get_container_len ( ) ;
190
197
191
198
if !self . hidden_containers . is_empty ( ) {
@@ -289,6 +296,7 @@ impl AppData {
289
296
/// Remove the sorted header & order, and sort by default - created datetime
290
297
pub fn reset_sorted ( & mut self ) {
291
298
self . set_sorted ( None ) ;
299
+ self . redraw . set_true ( ) ;
292
300
}
293
301
294
302
/// Sort containers based on a given header, if headings match, and already ascending, remove sorting
@@ -309,10 +317,19 @@ impl AppData {
309
317
self . sorted_by
310
318
}
311
319
320
+ /// Get a vec of the containers ID's
321
+ fn get_current_ids ( & self ) -> Vec < ContainerId > {
322
+ self . containers
323
+ . items
324
+ . iter ( )
325
+ . map ( |i| i. id . clone ( ) )
326
+ . collect :: < Vec < _ > > ( )
327
+ }
312
328
/// Sort the containers vec, based on a heading (and if clash, then by name), either ascending or descending,
313
329
/// If not sort set, then sort by created time
314
330
pub fn sort_containers ( & mut self ) {
315
331
if let Some ( ( head, ord) ) = self . sorted_by {
332
+ let pre_order = self . get_current_ids ( ) ;
316
333
let sort_closure = |a : & ContainerItem , b : & ContainerItem | -> std:: cmp:: Ordering {
317
334
let item_ord = match ord {
318
335
SortedOrder :: Asc => ( a, b) ,
@@ -372,13 +389,19 @@ impl AppData {
372
389
. then_with ( || item_ord. 0 . id . cmp ( & item_ord. 1 . id ) ) ,
373
390
}
374
391
} ;
392
+
375
393
self . containers . items . sort_by ( sort_closure) ;
376
- } else {
394
+ if pre_order != self . get_current_ids ( ) {
395
+ self . redraw . set_true ( ) ;
396
+ }
397
+ } else if self . current_sorted_id != self . get_current_ids ( ) {
377
398
self . containers . items . sort_by ( |a, b| {
378
399
a. created
379
400
. cmp ( & b. created )
380
401
. then_with ( || a. name . get ( ) . cmp ( b. name . get ( ) ) )
381
402
} ) ;
403
+ self . redraw . set_true ( ) ;
404
+ self . current_sorted_id = self . get_current_ids ( ) ;
382
405
}
383
406
}
384
407
@@ -414,21 +437,25 @@ impl AppData {
414
437
/// Select the first container
415
438
pub fn containers_start ( & mut self ) {
416
439
self . containers . start ( ) ;
440
+ self . redraw . set_true ( ) ;
417
441
}
418
442
419
443
/// select the last container
420
444
pub fn containers_end ( & mut self ) {
421
445
self . containers . end ( ) ;
446
+ self . redraw . set_true ( ) ;
422
447
}
423
448
424
449
/// Select the next container
425
450
pub fn containers_next ( & mut self ) {
426
451
self . containers . next ( ) ;
452
+ self . redraw . set_true ( ) ;
427
453
}
428
454
429
455
/// select the previous container
430
456
pub fn containers_previous ( & mut self ) {
431
457
self . containers . previous ( ) ;
458
+ self . redraw . set_true ( ) ;
432
459
}
433
460
434
461
/// Get ListState of containers
@@ -521,6 +548,11 @@ impl AppData {
521
548
self . get_selected_container ( ) . map ( |i| i. id . clone ( ) )
522
549
}
523
550
551
+ /// Check if a given ID matches the currently selected container
552
+ pub fn is_selected_container ( & self , id : & ContainerId ) -> bool {
553
+ self . get_selected_container ( ) . is_some_and ( |i| & i. id == id)
554
+ }
555
+
524
556
/// Get the Id and State for the currently selected container - used by the exec check method
525
557
pub fn get_selected_container_id_state_name ( & self ) -> Option < ( ContainerId , State , String ) > {
526
558
self . get_selected_container ( )
@@ -545,27 +577,31 @@ impl AppData {
545
577
pub fn docker_controls_next ( & mut self ) {
546
578
if let Some ( i) = self . get_mut_selected_container ( ) {
547
579
i. docker_controls . next ( ) ;
580
+ self . redraw . set_true ( ) ;
548
581
}
549
582
}
550
583
551
584
/// Change selected choice of docker commands of selected container
552
585
pub fn docker_controls_previous ( & mut self ) {
553
586
if let Some ( i) = self . get_mut_selected_container ( ) {
554
587
i. docker_controls . previous ( ) ;
588
+ self . redraw . set_true ( ) ;
555
589
}
556
590
}
557
591
558
592
/// Change selected choice of docker commands of selected container
559
593
pub fn docker_controls_start ( & mut self ) {
560
594
if let Some ( i) = self . get_mut_selected_container ( ) {
561
595
i. docker_controls . start ( ) ;
596
+ self . redraw . set_true ( ) ;
562
597
}
563
598
}
564
599
565
600
/// Change selected choice of docker commands of selected container
566
601
pub fn docker_controls_end ( & mut self ) {
567
602
if let Some ( i) = self . get_mut_selected_container ( ) {
568
603
i. docker_controls . end ( ) ;
604
+ self . redraw . set_true ( ) ;
569
605
}
570
606
}
571
607
@@ -603,27 +639,31 @@ impl AppData {
603
639
pub fn log_next ( & mut self ) {
604
640
if let Some ( i) = self . get_mut_selected_container ( ) {
605
641
i. logs . next ( ) ;
642
+ self . redraw . set_true ( ) ;
606
643
}
607
644
}
608
645
609
646
/// select previous selected log line
610
647
pub fn log_previous ( & mut self ) {
611
648
if let Some ( i) = self . get_mut_selected_container ( ) {
612
649
i. logs . previous ( ) ;
650
+ self . redraw . set_true ( ) ;
613
651
}
614
652
}
615
653
616
654
/// select last selected log line
617
655
pub fn log_end ( & mut self ) {
618
656
if let Some ( i) = self . get_mut_selected_container ( ) {
619
657
i. logs . end ( ) ;
658
+ self . redraw . set_true ( ) ;
620
659
}
621
660
}
622
661
623
662
/// select first selected log line
624
663
pub fn log_start ( & mut self ) {
625
664
if let Some ( i) = self . get_mut_selected_container ( ) {
626
665
i. logs . start ( ) ;
666
+ self . redraw . set_true ( ) ;
627
667
}
628
668
}
629
669
@@ -664,12 +704,14 @@ impl AppData {
664
704
/// Remove single app_state error
665
705
pub fn remove_error ( & mut self ) {
666
706
self . error = None ;
707
+ self . redraw . set_true ( ) ;
667
708
}
668
709
669
710
/// Insert single app_state error
670
711
pub fn set_error ( & mut self , error : AppError , gui_state : & Arc < Mutex < GuiState > > , status : Status ) {
671
712
gui_state. lock ( ) . status_push ( status) ;
672
713
self . error = Some ( error) ;
714
+ self . redraw . set_true ( ) ;
673
715
}
674
716
675
717
/// Check if the selected container is a dockerised version of oxker
@@ -758,6 +800,9 @@ impl AppData {
758
800
container. tx . update ( tx) ;
759
801
container. mem_limit . update ( mem_limit) ;
760
802
}
803
+ if self . is_selected_container ( id) {
804
+ self . redraw . set_true ( ) ;
805
+ }
761
806
self . sort_containers ( ) ;
762
807
}
763
808
@@ -793,6 +838,9 @@ impl AppData {
793
838
// Check is some, else can cause out of bounds error, if containers get removed before a docker update
794
839
if self . containers . items . get ( index) . is_some ( ) {
795
840
self . containers . items . remove ( index) ;
841
+ if self . is_selected_container ( id) {
842
+ self . redraw . set_true ( ) ;
843
+ }
796
844
}
797
845
}
798
846
}
@@ -872,6 +920,7 @@ impl AppData {
872
920
}
873
921
}
874
922
}
923
+ // self.redraw.set_true("update_containers");
875
924
}
876
925
}
877
926
@@ -919,6 +968,9 @@ impl AppData {
919
968
container. logs . end ( ) ;
920
969
}
921
970
}
971
+ if self . is_selected_container ( id) {
972
+ self . redraw . set_true ( ) ;
973
+ }
922
974
}
923
975
}
924
976
}
0 commit comments