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

Word wrapping in preview #1089

Open
1 task
mskvsk opened this issue May 26, 2024 · 9 comments
Open
1 task

Word wrapping in preview #1089

mskvsk opened this issue May 26, 2024 · 9 comments
Labels
feature New feature request good first issue Good for newcomers

Comments

@mskvsk
Copy link

mskvsk commented May 26, 2024

Please describe the problem you're trying to solve

Word wrapping in preview has been a pretty contentious issue in the discussions of at least two terminal file managers. Some people like to scroll it, some people prefer it to word wrap.

Personally, I would like some of my documents to word wrap, while the others and code to not to.

I suspect, many people have their own expectations around that which I will try to address in the solution.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

An optional "wrap" field in the previewers array in yazi.toml

True for word wrapping, false for long lines. The default is false. Ignored if the active preview is not wrappable.

Example:

previewers = [
	{ name = "*/", run = "folder", sync = true },
	# Code
	{ mime = "text/*", run = "code" },
	{ mime = "*/{xml,javascript,x-wine-extension-ini}", run = "code" },
	# JSON
	{ mime = "application/json", run = "json", wrap = true},
]

Additional context

No response

@mskvsk mskvsk added the feature New feature request label May 26, 2024
@mskvsk
Copy link
Author

mskvsk commented Jun 4, 2024

Also, I have never written any Rust but can give it a shot if @sxyazi deems this feature good to have.

We can also downscale the scope of this feature to a single boolean (wordwrap = true/false) in the config if it seems an overkill.

All I need is my text files to word wrap as I use text preview on them daily.

@sxyazi
Copy link
Owner

sxyazi commented Jun 6, 2024

Nice to have!

Would you like to raise a PR for it? Here is the method that handles code highlighting:

pub async fn highlight(&self, skip: usize, limit: usize) -> Result<Text<'static>, PeekError> {

Maybe we can change its function signature to:

pub async fn highlight(&self, skip: usize, area: Rect, wrap: bool) -> Result<Text<'static>, PeekError> {

And handle text wrapping when wrap = true.

@mskvsk
Copy link
Author

mskvsk commented Jun 8, 2024

Sure, will do. I'm half-way through the solution already.

@sxyazi sxyazi added the good first issue Good for newcomers label Jun 11, 2024
@sxyazi
Copy link
Owner

sxyazi commented Jun 11, 2024

If anyone is interested in implementing it, #1142 would be a great starting point.

@mskvsk
Copy link
Author

mskvsk commented Jun 16, 2024

I might also add that I am ready to pay a small bounty of $50 in crypto (USDC/USDT) to anyone who solves this issue without using an external crate (I don't mind if you copypaste the solution from the crate I have used in my PR).

This feature is quite nice to have to me, as I use Yazi to browse a lot of personal content that is stored as separate text files which don't look good without wrapping.

@ArtyomArtamonov
Copy link

Hello @mskvsk, I tried to solve this problem in #1159. Your previous commits helped me a bit, so thanks for that! You can try and build my solution, check it out on your use cases, maybe you will find some bugs. Feel free to comment and review my code!

@ArtyomArtamonov
Copy link

I found an issue with files that are handled by plugins, like json, toml etc. They use preview_widgets, not preview_code function. But file.lua plugin has word wrapping functionality in it, handled by Lua. Should Rust application handle the word wrapping or this is responsibility of plugins?

@mskvsk
Copy link
Author

mskvsk commented Jun 17, 2024

Thank you, I tried it out and have left some comments!

@sxyazi
Copy link
Owner

sxyazi commented Jun 18, 2024

Thanks for the PR @ArtyomArtamonov! I'll review it ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants