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

Query window pixel size #166

Merged
merged 2 commits into from
Oct 16, 2020
Merged

Query window pixel size #166

merged 2 commits into from
Oct 16, 2020

Conversation

swsnr
Copy link
Owner

@swsnr swsnr commented Oct 16, 2020

Query the window pixel size from the underlying terminal, and use it for Kitty image drawing.

Since term_size doesn't expose ws_xpixel/ws_ypixel (see clap-rs/term_size-rs#33) we do the ioctl ourselves. Getting rid of term_size also allows us to query the controlling terminal with ctermid (which term_size doesn't support either, see clap-rs/term_size-rs#34), which works even when all standard streams are redirected.

@swsnr swsnr self-assigned this Oct 16, 2020
@swsnr swsnr force-pushed the get-term-size-directly branch 2 times, most recently from 1339fd9 to e88bd82 Compare October 16, 2020 11:07
mdcat needs the window size in pixels to correctly draw images in some
terminals.  Unfortunately term_size doesn't expose ws_xpixel/ws_ypixel
from the winsize struct so we now do the ioctl ourselves.

This effectively gets rid of term_size on Unix system which has the
added benefit that we can now freely choose which device to query
instead of being limited to stdin, stdout and stderr.

We use this opportunity to query the controlling terminal directly, via
ctermid.  This implies that mdcat correctly detects the terminal size
even when all standard streams are redirected.
No longer run kitty icat --print-window-size to determine the window
size in pixels; instead rely on what we've got from the terminal
directly (kitty icat --print-window-size does nothing different).

This is simpler, faster and, above all, works over SSH connections.
@swsnr swsnr merged commit a5ab0dd into main Oct 16, 2020
@swsnr swsnr deleted the get-term-size-directly branch October 16, 2020 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant