Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contextual preview panel visibility #1708

Closed
2 of 3 tasks
Acumane opened this issue Sep 30, 2024 · 1 comment
Closed
2 of 3 tasks

Contextual preview panel visibility #1708

Acumane opened this issue Sep 30, 2024 · 1 comment
Labels
feature New feature request

Comments

@Acumane
Copy link

Acumane commented Sep 30, 2024

yazi --debug output

N/A

Please describe the problem you're trying to solve

Only show the preview panel for certain MIME types and optionally hide it on error/unsupported types.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

Example: I really only care to see previews of images

# yazi.toml
[open]
rules = [
	# Folder
	{ name = "*/", use = [ "edit", "open", "reveal" ], preview = false },
	# Text
	{ mime = "text/*", use = [ "edit", "reveal" ], preview = false },
	# Image
	{ mime = "image/*", use = [ "open", "reveal" ], preview = true  },
	# ...
]

(I know it's under [open] but we're already enumerating MIME types here, so...)

Additional context

No response

Validations

  • I have searched the existing issues/discussions
  • The latest nightly build of Yazi doesn't already have this feature
@Acumane Acumane added the feature New feature request label Sep 30, 2024
@sxyazi
Copy link
Owner

sxyazi commented Sep 30, 2024

We already have the hide-preview.yazi plugin, and it provides an API to do so.

Based on that, implementing your request is very easy and only requires a few lines of Lua code, save these lines as ~/.config/yazi/plugins/contextual-preview.yazi/init.lua:

local function setup()
  ps.sub("hover", function()
    local h = cx.active.current.hovered
    if not h then
      return
    end

    local is_image = (h:mime() or ""):find("image/") ~= nil
    if is_image == require("hide-preview"):enabled() then
      require("hide-preview"):entry()
    end
  end)
end

return { setup = setup }

Then enable it in your init.lua:

require("contextual-preview"):setup()
screenshot-002047.mp4

@sxyazi sxyazi closed this as completed Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants