diff --git a/src/core/app.rs b/src/core/app.rs index d4d7267..0b1df0e 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -218,7 +218,8 @@ impl Calcifer { } else if ui.button(&file.name).clicked() { self.open_file(Some(&file.path)); } - return false; + + false } } diff --git a/src/panels/file_tree.rs b/src/panels/file_tree.rs index a75eb2b..dfdd99c 100644 --- a/src/panels/file_tree.rs +++ b/src/panels/file_tree.rs @@ -34,82 +34,6 @@ impl FileEntry { } } -pub fn generate_file_tree(path: &Path, depth: isize) -> Option { - if let Some(file_name) = path.file_name() { - if file_name.to_string_lossy().starts_with('.') { - return None; - } - let extension = path.extension().and_then(|ext| ext.to_str()); - if !ALLOWED_FILE_EXTENSIONS.contains(&extension.unwrap_or_default()) { - return None; - } - } else { - return None; - } - - let name = path - .file_name() - .unwrap_or_else(|| OsStr::new("")) - .to_string_lossy() - .into_owned(); - - if !path.is_dir() { - return Some(FileEntry::new_entry(name, path.to_path_buf())); - } - - if depth < 0 { - return Some(FileEntry::end_of_branch(name, path.to_path_buf())); - } - - match fs::read_dir(path) { - Err(err) => Some(FileEntry::new_entry( - format!("Error reading directory: {}", err), - path.to_path_buf(), - )), - Ok(entries) => { - let mut paths: Vec> = entries - .map(|r| r.map_err(|e| io::Error::new(io::ErrorKind::Other, e))) - .collect(); - - paths.sort_by(|a, b| match (a, b) { - (Ok(entry_a), Ok(entry_b)) => sort_directories_first(entry_a, entry_b), - (Err(_), Ok(_)) => std::cmp::Ordering::Greater, - (Ok(_), Err(_)) => std::cmp::Ordering::Less, - (Err(_), Err(_)) => std::cmp::Ordering::Equal, - }); - - let mut folder_content = Vec::new(); - - for result in paths { - match result { - Ok(entry) => { - if let Some(file) = generate_file_tree(&entry.path(), depth - 1) { - folder_content.push(file); - } - } - Err(err) => { - folder_content.push(FileEntry::new_entry( - format!("Error reading entry: {}", err), - path.to_path_buf(), - )); - } - } - } - - if folder_content.is_empty() { - return None; - } - - Some(FileEntry { - name, - path: path.to_path_buf(), - folder_content: Some(folder_content), - content_checked: true, - }) - } - } -} - pub fn update_file_tree(file: FileEntry, opened_dirs: Vec) -> FileEntry { if opened_dirs.contains(&file.name) { if let Some(folder_content) = &file.folder_content { @@ -120,17 +44,17 @@ pub fn update_file_tree(file: FileEntry, opened_dirs: Vec) -> FileEntry .iter() .map(|entry| update_file_tree(entry.clone(), opened_dirs.clone())) .collect(); - return FileEntry { + FileEntry { name: file.name, path: file.path, folder_content: Some(updated_content), content_checked: true, - }; + } } else { - return file; + file } } else { - return file; + file } } @@ -182,7 +106,10 @@ pub fn generate_folder_entry(path: &Path) -> FileEntry { } } } else { - FileEntry::new_entry(format!("Error reading directory name"), path.to_path_buf()) + FileEntry::new_entry( + "Error reading directory name".to_string(), + path.to_path_buf(), + ) } } @@ -208,7 +135,7 @@ fn generate_entry(path: &Path) -> Option { if !path.is_dir() { return Some(FileEntry::new_entry(name, path.to_path_buf())); } - return Some(FileEntry::end_of_branch(name, path.to_path_buf())); + Some(FileEntry::end_of_branch(name, path.to_path_buf())) } fn sort_directories_first(a: &std::fs::DirEntry, b: &std::fs::DirEntry) -> Ordering { diff --git a/src/panels/terminal/linux_terminal.rs b/src/panels/terminal/linux_terminal.rs index 025146f..1bf360a 100644 --- a/src/panels/terminal/linux_terminal.rs +++ b/src/panels/terminal/linux_terminal.rs @@ -67,17 +67,27 @@ impl CommandEntry { pub fn update(&mut self) { if let Some(buffer) = &mut self.buffer { let mut output = String::new(); - let _ = buffer.output_buffer.read_line(&mut output); - if !remove_line_break(output.to_string()).is_empty() { - self.result.push(Line::output(format!("{}\n", output))); + loop { + let _ = buffer.output_buffer.read_line(&mut output); + if !remove_line_break(output.to_string()).is_empty() { + self.result.push(Line::output(format!("{}\n", output))); + output = "".to_string() + } else { + break; + } } + let mut error = String::new(); - let _ = buffer.error_buffer.read_line(&mut error); - if !remove_line_break(error.to_string()).is_empty() { - self.result.push(Line::error(format!("{}\n", error))); + loop { + let _ = buffer.error_buffer.read_line(&mut error); + if !remove_line_break(error.to_string()).is_empty() { + self.result.push(Line::error(format!("{}\n", error))); + error = "".to_string() + } else { + break; + } } - } - if let Some(buffer) = &mut self.buffer { + if let Ok(Some(_exit_status)) = buffer.child.try_wait() { //self.result.push(Line::output(format!("Command finished with status: {:?}\n", exit_status))); self.finished = true;