diff --git a/random_file_picker/tui.py b/random_file_picker/tui.py index 19f7909..95119da 100644 --- a/random_file_picker/tui.py +++ b/random_file_picker/tui.py @@ -84,6 +84,13 @@ class MenuApp(App[None]): self.current_index = 0 self.display_current_file() + def assert_current_file_exists(self) -> bool: + """Check if the current file exists and update the status label accordingly.""" + if not self.current_file or not self.current_file.exists(): + self.query_one("#status", Label).update(f"❌ File '{self.current_file}' not found") + return False + return True + def display_current_file(self) -> None: """Display the current file based on current_index.""" if not self.usable_files or self.current_index >= len(self.usable_files): @@ -123,6 +130,9 @@ class MenuApp(App[None]): if not self.current_file: return + if not self.assert_current_file_exists(): + return + self.query_one("#status", Label).update(f"📝 Open {self.current_file}") try: if self.use_geeqie and str(self.current_file).lower().endswith(tuple(IMG_EXTENSIONS)): @@ -139,6 +149,9 @@ class MenuApp(App[None]): if not self.current_file: return + if not self.assert_current_file_exists(): + return + try: self.query_one("#status", Label).update(f"⏳ Uploading {self.current_file.name} to webhook...") upload_file(self.current_file) @@ -151,6 +164,9 @@ class MenuApp(App[None]): if not self.current_file or self.current_index >= len(self.usable_files): return + if not self.assert_current_file_exists(): + return + try: self.current_file.unlink() _ = self.usable_files.pop(self.current_index) @@ -172,6 +188,9 @@ class MenuApp(App[None]): if not self.current_file or self.current_index >= len(self.usable_files): return + if not self.assert_current_file_exists(): + return + try: move_file_to_move_folder(self.current_file) _ = self.usable_files.pop(self.current_index) @@ -193,6 +212,9 @@ class MenuApp(App[None]): if not self.current_file: return + if not self.assert_current_file_exists(): + return + open_file_in_dolphin(self.current_file) self.query_one("#status", Label).update("📂 Opened file in folder")