diff --git a/src/main.rs b/src/main.rs index 91f0fdf..b052381 100644 --- a/src/main.rs +++ b/src/main.rs @@ -237,7 +237,7 @@ impl PreviewWidget<'_> { } fn not_a_dir(&mut self, absolute_path: &PathBuf) { - match absolute_path.is_file() { + match absolute_path.exists() && absolute_path.is_file() { true => { let block = Block::new() .borders(Borders::ALL) @@ -254,7 +254,11 @@ impl PreviewWidget<'_> { self.invalid_data(); } ErrorKind::PermissionDenied => self.permission_denied(), - _ => panic!("Problem with reading the contents of the file:\n{err:?}"), + _ => { + self.list = List::new(vec!["Cannot read file"]) + .block(block) + .style(Color::Red) + } }, } } @@ -264,11 +268,15 @@ impl PreviewWidget<'_> { .padding(Padding::symmetric(1, 1)) .fg(Color::Blue); - self.list = List::new(vec![ - "This is neither a directory or a file\nI have no idea what to do with this", - ]) - .block(block) - .style(Color::Red) + if absolute_path.exists() { + self.list = List::new(vec!["This is neither a directory\nOr a file"]) + .block(block) + .style(Color::Red) + } else { + self.list = List::new(vec!["This file does not exist anymore"]) + .block(block) + .style(Color::Red) + } } } }