3 ms·
No, there is an escape code that queries the window size in pixels: "\x1b[14t" Combined with the escape code that queries the window size in character cel
by KirillPanov 3y ago
No, there is an escape code that queries the window size in pixels:
"\x1b[14t"
Combined with the escape code that queries the window size in character cells ("\x1b[18t"), you can calculate the number of pixels per character cell (the "pixel size").
- the_gipsy 3y agoAre these escape codes actually implemented in the average terminal? I recently tried to get e.g. alacritty to tell me this stuff but I don't even know how you're supposed to red back the response.
- kps 3y agoYes, every xterm-compatible should have them. You just send the particular query (e.g. ‘CSI 14 t’) and the terminal sends back a response in the defined form¹. Of course you'll want raw mode, echo off, etc. Normally a library like curses does this for you. If you want to see, https://gist.github.com/kpschoedel/6a87ec2157ce2140be69193d18e14e3e https://gist.github.com/kpschoedel/6a87ec2157ce2140be69193d1... (I just whipped this up to answer the question; don't expect production quality) ¹ https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-F...
- the_gipsy 3y agoThank you so much! I will incorporate this to my sixel feature branch of a tui matrix client. Memes in the terminal!
- syrrim 3y agoMost implementations I've seen use an ioctl to query those particular bits. That's implemented quite reliably, since the same ioctl is used for character size as window size. Some implementations just set the character size to zero though.
- kevin_thibedeau 3y agoIoctl doesn't work over a serial port. The escape code queries are more general.
- kps 3y ago‘CSI 16 t’ reports the character size in pixels directly.