1+ use colored:: Colorize ;
12use rw3d_core:: packet:: WitcherPacket ;
23use rw3d_core:: utils:: { scripts_execute_formatter, scripts_root_path_formatter, mod_list_formatter, opcode_formatter, var_list_formatter, scripts_reload_formatter, scripts_reload_response_type, ScriptsReloadResponseType } ;
34
45
56
67pub ( crate ) trait HandleResponse {
7- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) ;
8- fn should_exit ( & self ) -> bool ;
8+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) ;
9+ fn is_done ( & self ) -> bool ;
910}
1011
1112
1213
13- pub ( crate ) struct ScriptsReloadHandler {
14+ pub ( crate ) struct ScriptsReloadPrinter {
1415 has_finished : bool ,
1516 warnings : Vec < String > ,
1617 errors : Vec < String >
1718}
1819
19- impl ScriptsReloadHandler {
20+ impl ScriptsReloadPrinter {
2021 fn print_summary ( & self ) {
21- println ! ( "{} Errors, {} Warnings\n " , self . errors. len( ) , self . warnings. len( ) ) ;
22+ println ! ( "========== {} Errors, {} Warnings ========== \n " , self . errors. len( ) , self . warnings. len( ) ) ;
2223
2324 for e in & self . errors {
24- println ! ( "{}" , e) ;
25+ println ! ( "{}" , e. red ( ) ) ;
2526 }
2627
2728 println ! ( "" ) ; // empty line between errors and warnings
2829
2930 for w in & self . warnings {
30- println ! ( "{}" , w) ;
31+ println ! ( "{}" , w. yellow ( ) ) ;
3132 }
3233 }
3334}
3435
35- impl Default for ScriptsReloadHandler {
36+ impl Default for ScriptsReloadPrinter {
3637 fn default ( ) -> Self {
37- ScriptsReloadHandler {
38+ ScriptsReloadPrinter {
3839 has_finished : false ,
3940 warnings : Vec :: new ( ) ,
4041 errors : Vec :: new ( ) ,
4142 }
4243 }
4344}
4445
45- impl HandleResponse for ScriptsReloadHandler {
46- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) {
46+ impl HandleResponse for ScriptsReloadPrinter {
47+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
4748 let msg = scripts_reload_formatter ( & response) ;
4849
4950 if let Ok ( response_type) = scripts_reload_response_type ( & response) {
@@ -75,97 +76,97 @@ impl HandleResponse for ScriptsReloadHandler {
7576 }
7677 }
7778
78- fn should_exit ( & self ) -> bool {
79+ fn is_done ( & self ) -> bool {
7980 self . has_finished
8081 }
8182}
8283
8384
8485
85- pub ( crate ) struct ScriptsExecuteHandler ( ) ;
86+ pub ( crate ) struct ScriptsExecutePrinter ( ) ;
8687
87- impl HandleResponse for ScriptsExecuteHandler {
88- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) {
88+ impl HandleResponse for ScriptsExecutePrinter {
89+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
8990 if verbose_print {
9091 println ! ( "{:?}" , response) ;
9192 } else {
9293 println ! ( "{}" , scripts_execute_formatter( & response) ) ;
9394 }
9495 }
9596
96- fn should_exit ( & self ) -> bool {
97+ fn is_done ( & self ) -> bool {
9798 true // only one packet
9899 }
99100}
100101
101102
102103
103- pub ( crate ) struct ScriptsRootpathHandler ( ) ;
104+ pub ( crate ) struct ScriptsRootpathPrinter ( ) ;
104105
105- impl HandleResponse for ScriptsRootpathHandler {
106- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) {
106+ impl HandleResponse for ScriptsRootpathPrinter {
107+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
107108 if verbose_print {
108109 println ! ( "{:?}" , response) ;
109110 } else {
110111 println ! ( "{}" , scripts_root_path_formatter( & response) ) ;
111112 }
112113 }
113114
114- fn should_exit ( & self ) -> bool {
115+ fn is_done ( & self ) -> bool {
115116 true // only one packet
116117 }
117118}
118119
119120
120121
121- pub ( crate ) struct ModlistHandler ( ) ;
122+ pub ( crate ) struct ModlistPrinter ( ) ;
122123
123- impl HandleResponse for ModlistHandler {
124- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) {
124+ impl HandleResponse for ModlistPrinter {
125+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
125126 if verbose_print {
126127 println ! ( "{:?}" , response) ;
127128 } else {
128129 println ! ( "{}" , mod_list_formatter( & response) ) ;
129130 }
130131 }
131132
132- fn should_exit ( & self ) -> bool {
133+ fn is_done ( & self ) -> bool {
133134 true // only one packet
134135 }
135136}
136137
137138
138139
139- pub ( crate ) struct OpcodeHandler ( ) ;
140+ pub ( crate ) struct OpcodePrinter ( ) ;
140141
141- impl HandleResponse for OpcodeHandler {
142- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) {
142+ impl HandleResponse for OpcodePrinter {
143+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
143144 if verbose_print {
144145 println ! ( "{:?}" , response) ;
145146 } else {
146147 println ! ( "{}" , opcode_formatter( & response) ) ;
147148 }
148149 }
149150
150- fn should_exit ( & self ) -> bool {
151+ fn is_done ( & self ) -> bool {
151152 true // only one packet
152153 }
153154}
154155
155156
156157
157- pub ( crate ) struct VarlistHandler ( ) ;
158+ pub ( crate ) struct VarlistPrinter ( ) ;
158159
159- impl HandleResponse for VarlistHandler {
160- fn handle ( & mut self , response : WitcherPacket , verbose_print : bool ) {
160+ impl HandleResponse for VarlistPrinter {
161+ fn handle_response ( & mut self , response : WitcherPacket , verbose_print : bool ) {
161162 if verbose_print {
162163 println ! ( "{:?}" , response) ;
163164 } else {
164165 println ! ( "{}" , var_list_formatter( & response) ) ;
165166 }
166167 }
167168
168- fn should_exit ( & self ) -> bool {
169+ fn is_done ( & self ) -> bool {
169170 true // only one packet
170171 }
171172}
0 commit comments