1- use crate :: common:: { View , PRIMARY_COLOR } ;
1+ use crate :: common:: { View , SELECTED_COLOR } ;
22use ratatui:: {
3+ style:: Style ,
34 text:: Line ,
45 widgets:: { ListItem , ListState } ,
56} ;
@@ -10,23 +11,38 @@ pub(crate) struct Model {
1011 pub ( crate ) running_state : RunningState ,
1112 pub ( crate ) file_path : String ,
1213 pub ( crate ) lines : Lines ,
14+ pub ( crate ) selected_count : usize ,
1315 pub ( crate ) message : Option < UserMessage > ,
1416 pub ( crate ) save_on_exit : bool ,
1517}
1618
19+ impl Model {
20+ pub ( crate ) fn default ( file_path : String , lines : & Vec < String > , save_on_exit : bool ) -> Self {
21+ Self {
22+ view : View :: List ,
23+ running_state : RunningState :: Running ,
24+ file_path,
25+ lines : Lines :: from ( lines) ,
26+ selected_count : 0 ,
27+ message : None ,
28+ save_on_exit,
29+ }
30+ }
31+ }
32+
1733#[ derive( Debug ) ]
1834pub ( crate ) struct Lines {
1935 pub ( crate ) items : Vec < LineItem > ,
2036 pub ( crate ) state : ListState ,
2137}
2238
23- #[ derive( Debug ) ]
39+ #[ derive( Debug , Clone ) ]
2440pub ( crate ) struct LineItem {
2541 pub ( crate ) content : String ,
2642 pub ( crate ) status : Selected ,
2743}
2844
29- #[ derive( Debug ) ]
45+ #[ derive( Debug , Clone , PartialEq ) ]
3046pub ( crate ) enum Selected {
3147 Yes ,
3248 No ,
@@ -74,10 +90,16 @@ impl LineItem {
7490 }
7591 }
7692
77- pub ( crate ) fn toggle ( & mut self ) {
93+ pub ( crate ) fn toggle ( & mut self ) -> bool {
7894 match self . status {
79- Selected :: Yes => self . status = Selected :: No ,
80- Selected :: No => self . status = Selected :: Yes ,
95+ Selected :: Yes => {
96+ self . status = Selected :: No ;
97+ false
98+ }
99+ Selected :: No => {
100+ self . status = Selected :: Yes ;
101+ true
102+ }
81103 }
82104 }
83105}
@@ -86,7 +108,10 @@ impl From<&LineItem> for ListItem<'_> {
86108 fn from ( value : & LineItem ) -> Self {
87109 let line = match value. status {
88110 Selected :: No => Line :: from ( value. content . clone ( ) ) ,
89- Selected :: Yes => Line :: styled ( value. content . clone ( ) , PRIMARY_COLOR ) ,
111+ Selected :: Yes => Line :: styled (
112+ format ! ( "> {}" , value. content. clone( ) ) ,
113+ Style :: new ( ) . fg ( SELECTED_COLOR ) ,
114+ ) ,
90115 } ;
91116 ListItem :: new ( line)
92117 }
0 commit comments