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

Support for Krita's .kra files #2239

Open
2 of 3 tasks
s-and-witch opened this issue Jan 23, 2025 · 6 comments
Open
2 of 3 tasks

Support for Krita's .kra files #2239

s-and-witch opened this issue Jan 23, 2025 · 6 comments
Labels
feature New feature request

Comments

@s-and-witch
Copy link

yazi --debug output

Not relevant

Please describe the problem you're trying to solve

Krita is an open-source painting program. Krita documents (link to a documentation) have .kra extension, but essentially are just a renamed zip archives with well known file structure. As yazi doesn't special-case them, it display zip archive guts. However, krita files could be handled in a better way.

This is how yazi handle .kra files

Image

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

Each .kra archive share some common properties. Here is his top-level structure:

$ unzip hg.kra -d hg
$ ls hg
Unnamed/  documentinfo.xml  maindoc.xml  mergedimage.png  mimetype  preview.png

Interesting files are mergedimage.png, mimetype and preview.png. Mimetype should always contain applicaiton/x-krita:

$ cat hg/mimetype
application/x-krita

And it's even detected by file utility:

$ file hg.kra
hg.kra: Zip data (MIME type "application/x-krita"?)

This should be enough to determine if we are dealing with krita file or not.

preview.png is a shrinked preview of a document with a bigger side equal to 256 pixels. However, I would suggest you to use mergedimage.png file. It has the same content, but isn't shrinked, so user would have a better quality preview.

So, here is how I think this should work:

  1. We spot that selected file has .kra extension
  2. Now we should try to interpret it as Krita document.
  3. (Optional) Check for mimetype to ensure, that this is really a krita document.
  4. Select mergedimage.png file
  5. Pass it the way yazi handles .png files.
  6. If something is wrong, then fallback to zip file handling.

Additional context

I'm not familiar with rust in general and with yazi code base in particular, so I'm not checking the mark above. However I may try to implement that by myself if you point me out to exact location where this logic should be implemented.

Checklist

  • I have searched the existing issues/discussions
  • The latest nightly build doesn't already have this feature
@s-and-witch s-and-witch added the feature New feature request label Jan 23, 2025
@sxyazi
Copy link
Owner

sxyazi commented Jan 23, 2025

You can implement it as a custom previewer via the Lua plugin system, https://yazi-rs.github.io/docs/plugins/overview#previewer

@s-and-witch
Copy link
Author

Ah, thank you for spotting this direction! I think, that should fit my needs, but I'm a little struggle to implement my logic. I have the following file structure:

 $ tree ~/.config/yazi
.
├── plugins
│   └── krita.yazi
│       ├── init.lua
│       ├── LICENSE
│       └── README.md
└── yazi.toml

With the following content of yazi.toml file:

[plugins]
prepend_previewers = [
  { name = "*.kra", run = "krita" }
]

preprend_preloaders = [
  { name = "*.kra", run = "krita" }
]

LICENSE and README.md files are currently empty. I inserted ya.dbg("krita plugin") into all three functions: M:seek, M:peek and M:preload. I'm also inserted one debug log into top-level of my plugin's init.lua file.

However, I don't see any message in yazi.log file except some irrelevant lines from yazi-adapter/src/emulator.rs file. Did I miss some important step? How can I investigate this issue?

@sxyazi
Copy link
Owner

sxyazi commented Jan 23, 2025

Use prepend_* instead of append_*, you can spot on your file to see what previewer is used

@s-and-witch
Copy link
Author

Use prepend_* instead of append_*

Yeah, I'm already using that and it included into my previous comment. I've found, that I had a typo in "prepend_preloaders", but fix changed nothing.

spot says, that yazi picks archive as a previewer (that was expected).

@sxyazi
Copy link
Owner

sxyazi commented Jan 23, 2025

[plugins]

It should be [plugin], not [plugins]. Use this scheme to avoid any typos:

# A TOML linter such as https://taplo.tamasfe.dev/ can use this schema to validate your config.
# If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas.
"$schema" = "https://yazi-rs.github.io/schemas/yazi.json"

@s-and-witch
Copy link
Author

Ah, thank you, it works! And I've managed to display preview, so here it is: https://github.com/s-and-witch/krita-yazi-plugin

I'm heavily relaying on this particular example: https://github.com/sxyazi/yazi/blob/shipped/yazi-plugin/preset/plugins/pdf.lua

Do you have any suggestions? Maybe it is possible to use some plugin installer like packer for neovim?

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