diff --git a/applications/shell/src/lib.rs b/applications/shell/src/lib.rs index ea0d4a7ce..7d4786d53 100644 --- a/applications/shell/src/lib.rs +++ b/applications/shell/src/lib.rs @@ -1429,7 +1429,7 @@ impl Shell { let file_path = args[0]; self.less = true; - self.get_content_string(file_path.to_string()); + let _ = self.get_content_string(file_path.to_string()); self.terminal.lock().clear(); self.clear_cmdline(false)?; self.parse_content(); @@ -1461,6 +1461,7 @@ impl Shell { None => return Err("failed to get the byte indices of the last line") }; + info!("{}", self.content.len() - 1); self.terminal.lock().clear(); self.terminal.lock().print_to_terminal( self.content[start_indices.start..end_indices.end].to_string() @@ -1498,16 +1499,13 @@ impl Shell { previous_char = c; } self.map.insert(cur_line_num, LineSlice{ start: line_start_idx, end: self.content.len() }); - - for (line_num, line_slice) in &self.map { - self.terminal.lock().print_to_terminal(format!("Line {}: start = {}, end = {}\n", line_num, line_slice.start, line_slice.end).to_string()); - } } /// Stores the entire file as a string to be parsed by 'less' operation - fn get_content_string(&mut self, file_path: String) { + fn get_content_string(&mut self, file_path: String) -> Result{ let Ok(curr_wd) = task::with_current_task(|t| t.get_env().lock().working_dir.clone()) else { self.terminal.lock().print_to_terminal("failed to get current task".to_string()); + return Err("failed to get current task".to_string()); }; let curr_dir = self.env.lock().working_dir.lock().get_absolute_path(); @@ -1522,6 +1520,7 @@ impl Shell { // Checks if it is a directory FileOrDir::Dir(directory) => { self.terminal.lock().print_to_terminal(format!("{:?} a directory, cannot 'less' non-files.", directory.lock().get_name())); + return Err(format!("Failed to read directory").to_string()) } // Checks if it is a file and reads it into a utf8 string FileOrDir::File(file) => { @@ -1530,20 +1529,24 @@ impl Shell { let mut string_slice_as_bytes = vec![0; file_size]; if let Err(_e) = file_locked.read_at(&mut string_slice_as_bytes, 0) { self.terminal.lock().print_to_terminal("Failed to read error".to_string()); + return Err(format!("Failed to read file")); } let read_string = match str::from_utf8(&string_slice_as_bytes) { Ok(string_slice) => string_slice, Err(_utf8_err) => { self.terminal.lock().print_to_terminal("File was not a printable UTF-8 text file".to_string()); + return Err(format!("File was not a printable UTF-8 text file").to_string()); } }; // Stores the content of the file as a string self.content = read_string.to_string(); + Ok(read_string.to_string()) } } }, None => { self.terminal.lock().print_to_terminal(format!("Path not found: {}\n", path).to_string()); + return Err(format!("File was not found").to_string()); } } }