benjajaja / ratatui-image

Ratatui widget for rendering image graphics in terminals that support it
https://crates.io/crates/ratatui-image
MIT License
110 stars 16 forks source link

Picker::from_termios() for windows #32

Closed josueBarretogit closed 2 days ago

josueBarretogit commented 3 months ago

I looked at the definition of Picker::from_termios() in the source code and noticed it only is defined in unix systems, I wonder what should be done in the case of compiling for windows (how to get the font size on windows or alternatives), it would be nice if in the documentation there was a note describing what to do in such case or maybe if this method is called on windows then change the implementation accordingly

benjajaja commented 2 months ago

The Windows console API has some font-size info, but in "logical units": https://learn.microsoft.com/en-us/windows/console/console-font-infoex#members

It may be possible to convert this "logical unit" into pixels if you also query some other windows API for the DPI.

Note that I think that even the window-size might not be implemented on windows, I think that one comes from the ratatui backend.

josueBarretogit commented 2 months ago

I got a windows machine I'll try using the windows API, in the meantime what fontsize do you recommend for windows?

benjajaja commented 2 months ago

I have no idea, I guess that depends on the terminal and settings.

BTW I can confirm that not even window size is really implemented for windows for the ratatui backends: https://github.com/crossterm-rs/crossterm/blob/492b764f9f132d302903ff6f2f55e96c1b8cd0ec/src/terminal/sys/windows.rs#L64

I suggest playing around with the windows console API. Ultimately you would need both window size in pixels, not columns/rows, AND the font size in pixels, not some "logical unit".

benjajaja commented 2 months ago

If there's a way to get this information in any way, then we can try it out here and later move it all to the ratatui backends.

benjajaja commented 2 weeks ago

@josueBarretogit on master, there is now support for getting the font-size from some query, which should work on WSL.

For non-WSL, I believe rustix is not available. However it might be possible to query the terminal nonetheless. There's an empty non-rustix function now here: query_stdio_capabilities. Perhaps there is a way to send the stdin queries via the Windows Console API - I don't know.

benjajaja commented 2 days ago

@josueBarretogit this should work on master now.