sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
16.3k stars 377 forks source link

VSCode integrated terminal image preview distorted #446

Closed baitian752 closed 9 months ago

baitian752 commented 11 months ago

What system are you running Yazi on?

Windows

What terminal are you running Yazi in?

VSCode integrated terminal (VSCode 1.85.0)

Yazi version

yazi 0.1.5

Did you try the latest main branch to see if the problem has already been fixed?

Tried, but the problem is still present

Describe the bug

Remote SSH for my linux server

Run yazi image

View the first image (1024x1024, OK) image

Back to the text file (there is an image border) image

View the second image (1024x1536 distorted) image

The original image: 04_04

Expected Behavior

Preview is OK.

To Reproduce

As the bug description.

Configuration

No response

Anything else?

No response

baitian752 commented 11 months ago

After some tests, I found this issue is relative to the global zoom level of VSCode, but the color is not correct at zoom level 0.

image

sxyazi commented 11 months ago

Try reducing max_width and max_height to see if the issue still exists - Yazi cannot obtain the correct terminal pixel width and height for displaying images due to VSCode not implementing the ioctl(TIOCGWINSZ) system call. Therefore, fixed max_width and max_height are currently used. The issue you're describing is caused by images exceeding the available area and resulting in scrolling.

Another way to obtain pixel width and height is through CSI 14 t, but unfortunately, crossterm does not provide any way for users to extend it; it can only be added to the crossterm codebase. I've submitted a patch, but it hasn't been merged yet, https://github.com/crossterm-rs/crossterm/pull/810. So, currently, in VSCode, you can only limit the image size using max_width and max_height instead of dynamically adjusting based on terminal size.

As for image colors, this is the expected behavior. Currently, VSCode only supports Sixel graphics protocol, which is a rather old protocol that only supports 256 colors. So Yazi can only use approximate colors as substitute colors for display. Until VSCode supports more advanced protocols (such as Terminal graphics protocol or Inline images protocol protocols), it cannot be improved.

baitian752 commented 11 months ago

Thanks for you information. And for the colors, I have also test imgcat, which looks OK:

image

baitian752 commented 11 months ago

I have tried set preview size with max_width and max_height. It looks good, thank you.

image

sxyazi commented 10 months ago

Thanks for you information. And for the colors, I have also test imgcat, which looks OK:

I think this is not a bug, it's just that Yazi's default image compression strategy is more aggressive.

I'll add a new config option to allow users to adjust the compression level manually.

github-actions[bot] commented 8 months ago

I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.