Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/src/styles/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ img {
[class^="right-sidebar"] {
min-width: 20vw;
max-width: 300px;
pointer-events: none;
> .sl-container {
width: calc(25vw - (2 * var(--sidebar-pad-x)));
max-width: calc(300px - (2 * var(--sidebar-pad-x)));
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"textual-image[textual]>=0.8.4",
"textual-speedups>=0.2.1",
"tomli>=2.4.0",
"textual-video>=0.1.4",
]

[project.urls]
Expand Down
59 changes: 59 additions & 0 deletions src/rovr/classes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class RovrConfig(TypedDict, total=False):
"application/ms-opentype": "font",
"application/font-.*": "font",
"application/x-font-.*": "font",
"video/mp4": "video"
}
r""" Default value of the field path 'Rovr Config interface mime_rules' """

Expand Down Expand Up @@ -579,6 +580,9 @@ class _RovrConfigInterface(TypedDict, total=False):
image_viewer: "_RovrConfigInterfaceImageViewer"
r""" Settings related to the image viewer used in the preview sidebar """

video_viewer: "_RovrConfigInterfaceVideoViewer"
r""" Settings related to the video viewer used in the preview sidebar """

allow_tab_nav: bool
r"""
Allow navigating the main app screen with `tab` and `shift+tab`
Expand Down Expand Up @@ -637,6 +641,7 @@ class _RovrConfigInterface(TypedDict, total=False):
image/svg\+xml: resvg
inode/directory: folder
text/.*: text
video/mp4: video
"""


Expand Down Expand Up @@ -713,6 +718,45 @@ class _RovrConfigInterfaceImageViewer(TypedDict, total=False):
"""


class _RovrConfigInterfaceVideoViewer(TypedDict, total=False):
r"""Settings related to the video viewer used in the preview sidebar"""

protocol: "_RovrConfigInterfaceImageViewerProtocol"
r"""
The image protocol to use when displaying an video

default: Halfcell
"""

fps_decrease_factor: int
r"""
FPS decrease factor

default: 3
"""

pause_icon_type: "_RovrConfigInterfaceVideoViewerPauseIconType"
r"""
Pause button icon type.

default: nerd
"""

show_track: bool
r"""
Whether to show player track

default: True
"""

show_controls: bool
r"""
Whether to show player controls (pause button and time)

default: True
"""


_RovrConfigInterfaceImageViewerMaxSizeItem = int
r""" minimum: 1 """

Expand Down Expand Up @@ -767,6 +811,18 @@ class _RovrConfigInterfaceImageViewer(TypedDict, total=False):
_ROVRCONFIGINTERFACEIMAGEVIEWERRESAMPLING_HAMMING: Literal["hamming"] = "hamming"
r"""The values for the 'The resampling method to use when resizing images. This is only applicable when the image exceeds the maximum size specified in `max_size`' enum"""

_RovrConfigInterfaceVideoViewerPauseIconType = (
Literal["unicode"]
| Literal["emoji"]
| Literal["ascii"]
| Literal["nerd"]
)
r"""
Pause button icon type.

default: nerd
"""


_RovrConfigInterfaceMimeRulesAdditionalproperties = (
Literal["text"]
Expand All @@ -777,6 +833,7 @@ class _RovrConfigInterfaceImageViewer(TypedDict, total=False):
| Literal["remime"]
| Literal["resvg"]
| Literal["font"]
| Literal["video"]
)
_ROVRCONFIGINTERFACEMIMERULESADDITIONALPROPERTIES_TEXT: Literal["text"] = "text"
r"""The values for the '_RovrConfigInterfaceMimeRulesAdditionalproperties' enum"""
Expand All @@ -796,6 +853,8 @@ class _RovrConfigInterfaceImageViewer(TypedDict, total=False):
r"""The values for the '_RovrConfigInterfaceMimeRulesAdditionalproperties' enum"""
_ROVRCONFIGINTERFACEMIMERULESADDITIONALPROPERTIES_FONT: Literal["font"] = "font"
r"""The values for the '_RovrConfigInterfaceMimeRulesAdditionalproperties' enum"""
_ROVRCONFIGINTERFACEMIMERULESADDITIONALPROPERTIES_VIDEO: Literal["video"] = "video"
r"""The values for the '_RovrConfigInterfaceMimeRulesAdditionalproperties' enum"""


class _RovrConfigInterfacePreviewText(TypedDict, total=False):
Expand Down
2 changes: 1 addition & 1 deletion src/rovr/classes/type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Literal, TypeAlias

PreviewTypes: TypeAlias = Literal[
"text", "image", "pdf", "archive", "folder", "remime", "resvg", "font"
"text", "image", "pdf", "archive", "folder", "remime", "resvg", "font", "video"
]
SortByOptions: TypeAlias = Literal[
"name", "size", "modified", "created", "extension", "natural"
Expand Down
8 changes: 8 additions & 0 deletions src/rovr/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ scrolloff = 3
protocol = "Auto"
max_size = [4000, 4000]

[interface.video_viewer]
protocol = "Halfcell"
fps_decrease_factor = 3
pause_icon_type = 'unicode'
show_controls = true
show_track = true

[interface.preview_text]
error = "couldn't read this file! (\u00AC_\u00AC)" # ¬_¬
start = """
Expand Down Expand Up @@ -67,6 +74,7 @@ panels = false
"application/ms-opentype" = "font"
"application/font-.*" = "font"
"application/x-font-.*" = "font"
"video/mp4" = "video"

[settings]
copy_includes_metadata = true
Expand Down
43 changes: 40 additions & 3 deletions src/rovr/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,41 @@
}
}
},
"video_viewer": {
"type": "object",
"description": "Settings related to the video viewer used in the preview sidebar",
"additionalProperties": false,
"properties": {
"protocol": {
"type": "string",
"default": "Halfcell",
"description": "The image protocol to use when displaying an video",
"enum": ["Auto", "TGP", "Sixel", "Halfcell", "Unicode"]
},
"fps_decrease_factor": {
"type": "integer",
"default": 3,
"minimum": 1,
"description": "FPS decrease factor"
},
"pause_icon_type": {
"type": "string",
"default": "nerd",
"description": "Pause button icon type.",
"enum": ["nerd", "ascii", "emoji", "unicode"]
},
"show_track": {
"type": "boolean",
"default": true,
"description": "Whether to show player track"
},
"show_controls": {
"type": "boolean",
"default": true,
"description": "Whether to show player controls (pause button and time)"
}
}
},
"allow_tab_nav": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -179,7 +214,8 @@
"folder",
"remime",
"resvg",
"font"
"font",
"video"
]
},
"default": {
Expand All @@ -201,9 +237,10 @@
"font/.*": "font",
"application/ms-opentype": "font",
"application/font-.*": "font",
"application/x-font-.*": "font"
"application/x-font-.*": "font",
"video/mp4": "video"
},
"description": "Map MIME type patterns to preview types. Uses regex patterns. Valid preview types: text, image, pdf, archive, folder, resvg, font, remime.\n-> Use 'remime' if you want a more accurate description from file(1)"
"description": "Map MIME type patterns to preview types. Uses regex patterns. Valid preview types: text, image, pdf, archive, folder, resvg, font, remime, video.\n-> Use 'remime' if you want a more accurate description from file(1)"
}
}
},
Expand Down
26 changes: 26 additions & 0 deletions src/rovr/core/preview_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from textual.widget import Widget
from textual.widgets import Static
from textual.widgets.selection_list import Selection
from textual_video import VideoPlayer
from textual_video.enums import IconType, ImageType

from rovr.classes.archive import Archive, BadArchiveError
from rovr.classes.textual_options import (
Expand Down Expand Up @@ -349,6 +351,27 @@ def show_resvg_preview(self) -> None:
return
self.app.call_from_thread(setattr, self, "border_title", titles.svg)

def show_video_preview(self, depth: int = 0) -> None:
"""Show video preview. Runs in a thread."""
if should_cancel() or self._current_file_path is None:
return
self.app.call_from_thread(setattr, self, "border_title", titles.video)
self.app.call_from_thread(self.remove_children)

if should_cancel():
return
self.app.call_from_thread(self.mount, VideoPlayer(
self._current_file_path,
image_type=ImageType(config["interface"]["video_viewer"]["protocol"]),
fps_decrease_factor=config["interface"]["video_viewer"]["fps_decrease_factor"],
pause_icon_type=IconType(config["interface"]["video_viewer"]["pause_icon_type"]),
show_controls=config["interface"]["video_viewer"]["show_controls"],
show_track=config["interface"]["video_viewer"]["show_track"]
))

if should_cancel():
return

def show_image_preview(self, depth: int = 0) -> None:
"""Show image preview. Runs in a thread."""
if should_cancel() or self._current_file_path is None:
Expand Down Expand Up @@ -1052,6 +1075,9 @@ def update_ui(
elif file_type == "image":
self.log("Showing image preview")
self.show_image_preview()
elif file_type == "video":
self.log("Showing video preview")
self.show_video_preview()
elif file_type == "archive":
self.log("Showing archive preview")
self.show_archive_preview()
Expand Down
2 changes: 1 addition & 1 deletion src/rovr/functions/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def match_mime_to_preview_type(
widget: DOMNode,
mime_type: str,
) -> (
Literal["text", "image", "pdf", "archive", "folder", "remime", "resvg", "font"]
Literal["text", "image", "pdf", "archive", "folder", "remime", "resvg", "font", "video"]
| None
):
"""
Expand Down
1 change: 1 addition & 0 deletions src/rovr/variables/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class PreviewContainerTitles:
pdf = "PDF Preview"
svg = "SVG Preview"
font = "Font Preview"
video = "Video Preview"


buttons_that_depend_on_path = [
Expand Down
Loading