Skip to content

Commit 71e1b33

Browse files
fix(preview): add fallback title for special files and broken symlinks
1 parent ff86eac commit 71e1b33

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/rovr/core/preview_container.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464

6565
PREVIEWER_GROUP = "previewers"
6666
TEXT_PREVIEW_CACHE_VERSION = "windowed-v2"
67-
FONT_PREVIEW_CACHE_VERSION = "font-v2"
6867
BAT_PREVIEW_CACHE_VERSION = "paged-v2"
6968
BAT_PREVIEW_PAGE_SIZE = 256
7069
BAT_PREVIEWER_GROUP = "bat-pages"
@@ -359,9 +358,15 @@ async def file_not_found(
359358
return
360359
try:
361360
if dir_entry.is_symlink():
362-
await self.mount(
363-
Static("The symlink target is not found!", classes="special")
364-
)
361+
self.set_border("title", "Broken Symlink")
362+
try:
363+
target_path = os.readlink(location)
364+
msg = f"The symlink target is not found!\nTarget: {target_path}"
365+
except OSError:
366+
msg = "The symlink target is not found!"
367+
368+
await self.mount(Static(msg, classes="special"))
369+
365370
# also update option if necessary
366371
if isinstance(
367372
highlighted_option, FileListSelectionWidget
@@ -411,7 +416,7 @@ def show_font_preview(self) -> None:
411416
)
412417
return
413418
signature = (
414-
f"{FONT_PREVIEW_CACHE_VERSION}:{preview_utils.MAX_FONT_SIZE}:{config['interface']['font_preview']['font_size']}",
419+
f"{preview_utils.MAX_FONT_SIZE}:{config['interface']['font_preview']['font_size']}",
415420
f"{self._preview_texts['font_text']}:{fg_color.hex}:{bg_color.hex}:{NewImage.func.__name__}",
416421
)
417422
img = _load_cached_image(realpath, "font", stat_result, signature)
@@ -1652,8 +1657,7 @@ def mount_special_messages(self) -> None:
16521657
return
16531658
self.log(self._mime_type)
16541659
assert isinstance(self._current_content, str)
1655-
title = self._mime_type.method if self._mime_type else "Preview"
1656-
self.set_border("title", title)
1660+
self.set_border("title", self._mime_type.method if self._mime_type else "Preview")
16571661

16581662
display_content: str = self._current_content
16591663
if self._mime_type:

0 commit comments

Comments
 (0)