@@ -46,7 +46,7 @@ fn main() {
4646
4747 loop {
4848 let readline = rl. readline ( PROMPT ) ;
49- let mut current_statement = match readline {
49+ let current_statement = match readline {
5050 Ok ( line) => {
5151 rl. add_history_entry ( line. as_ref ( ) ) ;
5252 line
@@ -64,29 +64,33 @@ fn main() {
6464 }
6565 } ;
6666
67- current_statement = current_statement. trim ( ) . to_string ( ) ;
67+ interpret ( current_statement, & mut program, & mut conf) ;
68+ }
69+ }
6870
69- if & current_statement[ 0 ..1 ] == "~" {
70- match execute_command ( & current_statement, & mut program, & mut conf) {
71- Ok ( msg) => println ! ( "Command successfull => \n {}" , msg) ,
72- Err ( why) => println ! ( "{} => {}" , "Command failed" . bold( ) . red( ) , why)
73- }
74- continue ;
75- }
76-
71+ fn interpret ( input : String , program : & mut Program , conf : & mut Config ) {
72+ let current_statement = input. trim ( ) . to_string ( ) ;
7773
78- let stmt_type: StmsType = get_statement_type ( & current_statement) ;
79- program. push ( & current_statement, stmt_type) ;
74+ if & current_statement[ 0 ..1 ] == "~" {
75+ match execute_command ( & current_statement, program, conf) {
76+ Ok ( msg) => println ! ( "Command successfull => \n {}" , msg) ,
77+ Err ( why) => println ! ( "{} => {}" , "Command failed" . bold( ) . red( ) , why)
78+ }
79+ return ( ) ;
80+ }
81+
8082
81- let begin = Instant :: now ( ) ;
82- match program. run ( & conf) {
83- Err ( why) => {
84- println ! ( "{}: {}" , "--- Error Type:" . red( ) . bold( ) , why) ;
85- program. pop ( ) ;
86- } ,
87- Ok ( handle) => {
88- println ! ( "{}" , format_output_handle( & handle, begin) ) ;
89- }
83+ let stmt_type: StmsType = get_statement_type ( & current_statement) ;
84+ program. push ( & current_statement, stmt_type) ;
85+
86+ let begin = Instant :: now ( ) ;
87+ match program. run ( & conf) {
88+ Err ( why) => {
89+ println ! ( "{}: {}" , "--- Error Type:" . red( ) . bold( ) , why) ;
90+ program. pop ( ) ;
91+ } ,
92+ Ok ( handle) => {
93+ println ! ( "{}" , format_output_handle( & handle, begin) ) ;
9094 }
9195 }
9296}
0 commit comments