@@ -1429,7 +1429,7 @@ impl Shell {
1429
1429
1430
1430
let file_path = args[ 0 ] ;
1431
1431
self . less = true ;
1432
- self . get_content_string ( file_path. to_string ( ) ) ;
1432
+ let _ = self . get_content_string ( file_path. to_string ( ) ) ;
1433
1433
self . terminal . lock ( ) . clear ( ) ;
1434
1434
self . clear_cmdline ( false ) ?;
1435
1435
self . parse_content ( ) ;
@@ -1461,6 +1461,7 @@ impl Shell {
1461
1461
None => return Err ( "failed to get the byte indices of the last line" )
1462
1462
} ;
1463
1463
1464
+ info ! ( "{}" , self . content. len( ) - 1 ) ;
1464
1465
self . terminal . lock ( ) . clear ( ) ;
1465
1466
self . terminal . lock ( ) . print_to_terminal (
1466
1467
self . content [ start_indices. start ..end_indices. end ] . to_string ( )
@@ -1498,16 +1499,13 @@ impl Shell {
1498
1499
previous_char = c;
1499
1500
}
1500
1501
self . map . insert ( cur_line_num, LineSlice { start : line_start_idx, end : self . content . len ( ) } ) ;
1501
-
1502
- for ( line_num, line_slice) in & self . map {
1503
- self . terminal . lock ( ) . print_to_terminal ( format ! ( "Line {}: start = {}, end = {}\n " , line_num, line_slice. start, line_slice. end) . to_string ( ) ) ;
1504
- }
1505
1502
}
1506
1503
1507
1504
/// Stores the entire file as a string to be parsed by 'less' operation
1508
- fn get_content_string ( & mut self , file_path : String ) {
1505
+ fn get_content_string ( & mut self , file_path : String ) -> Result < String , String > {
1509
1506
let Ok ( curr_wd) = task:: with_current_task ( |t| t. get_env ( ) . lock ( ) . working_dir . clone ( ) ) else {
1510
1507
self . terminal . lock ( ) . print_to_terminal ( "failed to get current task" . to_string ( ) ) ;
1508
+ return Err ( "failed to get current task" . to_string ( ) ) ;
1511
1509
} ;
1512
1510
1513
1511
let curr_dir = self . env . lock ( ) . working_dir . lock ( ) . get_absolute_path ( ) ;
@@ -1522,6 +1520,7 @@ impl Shell {
1522
1520
// Checks if it is a directory
1523
1521
FileOrDir :: Dir ( directory) => {
1524
1522
self . terminal . lock ( ) . print_to_terminal ( format ! ( "{:?} a directory, cannot 'less' non-files." , directory. lock( ) . get_name( ) ) ) ;
1523
+ return Err ( format ! ( "Failed to read directory" ) . to_string ( ) )
1525
1524
}
1526
1525
// Checks if it is a file and reads it into a utf8 string
1527
1526
FileOrDir :: File ( file) => {
@@ -1530,20 +1529,24 @@ impl Shell {
1530
1529
let mut string_slice_as_bytes = vec ! [ 0 ; file_size] ;
1531
1530
if let Err ( _e) = file_locked. read_at ( & mut string_slice_as_bytes, 0 ) {
1532
1531
self . terminal . lock ( ) . print_to_terminal ( "Failed to read error" . to_string ( ) ) ;
1532
+ return Err ( format ! ( "Failed to read file" ) ) ;
1533
1533
}
1534
1534
let read_string = match str:: from_utf8 ( & string_slice_as_bytes) {
1535
1535
Ok ( string_slice) => string_slice,
1536
1536
Err ( _utf8_err) => {
1537
1537
self . terminal . lock ( ) . print_to_terminal ( "File was not a printable UTF-8 text file" . to_string ( ) ) ;
1538
+ return Err ( format ! ( "File was not a printable UTF-8 text file" ) . to_string ( ) ) ;
1538
1539
}
1539
1540
} ;
1540
1541
// Stores the content of the file as a string
1541
1542
self . content = read_string. to_string ( ) ;
1543
+ Ok ( read_string. to_string ( ) )
1542
1544
}
1543
1545
}
1544
1546
} ,
1545
1547
None => {
1546
1548
self . terminal . lock ( ) . print_to_terminal ( format ! ( "Path not found: {}\n " , path) . to_string ( ) ) ;
1549
+ return Err ( format ! ( "File was not found" ) . to_string ( ) ) ;
1547
1550
}
1548
1551
}
1549
1552
}
0 commit comments