@@ -335,6 +335,8 @@ impl Executor {
335
335
self . stack . push ( Type :: Bool ( token. parse ( ) . unwrap_or ( true ) ) ) ;
336
336
} else if chars[ 0 ] == '(' && chars[ chars. len ( ) - 1 ] == ')' {
337
337
// Push string value on the stack
338
+ self . stack
339
+ . push ( Type :: String ( token[ 1 ..token. len ( ) - 1 ] . to_string ( ) ) ) ;
338
340
let string = {
339
341
let mut buffer = String :: new ( ) ; // Temporary storage
340
342
let mut brackets = 0 ; // String's nest structure
@@ -380,6 +382,12 @@ impl Executor {
380
382
'r' => buffer. push_str ( "\\ r" ) ,
381
383
_ => buffer. push ( c) ,
382
384
}
385
+ buffer. push ( match c {
386
+ 'n' => '\n' ,
387
+ 't' => '\t' ,
388
+ 'r' => '\r' ,
389
+ _ => c,
390
+ } )
383
391
} else {
384
392
buffer. push ( c) ;
385
393
}
@@ -396,6 +404,8 @@ impl Executor {
396
404
buffer
397
405
} ;
398
406
self . stack . push ( Type :: String ( string) ) ;
407
+ self . stack
408
+ . push ( Type :: String ( token[ 1 ..token. len ( ) - 1 ] . to_string ( ) ) ) ;
399
409
} else if chars[ 0 ] == '[' && chars[ chars. len ( ) - 1 ] == ']' {
400
410
// Push list value on the stack
401
411
let old_len = self . stack . len ( ) ; // length of old stack
@@ -700,15 +710,10 @@ impl Executor {
700
710
// Standard output
701
711
"print" => {
702
712
let a = self . pop_stack ( ) . get_string ( ) ;
703
-
704
- let a = a. replace ( "\\ n" , "\n " ) ;
705
- let a = a. replace ( "\\ t" , "\t " ) ;
706
- let a = a. replace ( "\\ r" , "\r " ) ;
707
-
708
713
if let Mode :: Debug = self . mode {
709
714
println ! ( "[Output]: {a}" ) ;
710
715
} else {
711
- print ! ( "{a}" ) ;
716
+ println ! ( "{a}" ) ;
712
717
}
713
718
}
714
719
@@ -868,7 +873,6 @@ impl Executor {
868
873
return ;
869
874
}
870
875
}
871
-
872
876
self . log_print ( String :: from ( "Error! item not found in the list\n " ) ) ;
873
877
self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
874
878
}
@@ -1378,11 +1382,28 @@ impl Executor {
1378
1382
} )
1379
1383
}
1380
1384
1385
+ "cls" => {
1386
+ self . clearscreen ( ) ;
1387
+ }
1388
+
1389
+ "clear" => {
1390
+ self . clearscreen ( ) ;
1391
+ }
1392
+
1381
1393
// If it is not recognized as a command, use it as a string.
1382
1394
_ => self . stack . push ( Type :: String ( command) ) ,
1383
1395
}
1384
1396
}
1385
1397
1398
+ fn clearscreen ( & mut self ) {
1399
+ let result = clearscreen:: clear ( ) ;
1400
+ if result. is_err ( ) {
1401
+ println ! ( "Error! Failed to clear screen" ) ;
1402
+ self . stack
1403
+ . push ( Type :: Error ( String :: from ( "failed-to-clear-screen" ) ) ) ;
1404
+ }
1405
+ }
1406
+
1386
1407
/// Pop stack's top value
1387
1408
fn pop_stack ( & mut self ) -> Type {
1388
1409
if let Some ( value) = self . stack . pop ( ) {
0 commit comments