Skip to content

Commit

Permalink
fix clippy errors again
Browse files Browse the repository at this point in the history
  • Loading branch information
nnh12 committed Dec 6, 2024
1 parent b11c169 commit b8c6b0c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions applications/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<String, String>{
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();
Expand All @@ -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) => {
Expand All @@ -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());
}
}
}
Expand Down

0 comments on commit b8c6b0c

Please sign in to comment.