I've seen some posts and answers about how to get the terminal size in numbers of columns and rows. Can I get the terminal size, or equivalently, the size of the font used in the terminal, in pixels?
(I wrote equivalently because terminal width[px] = font width[px]*number of columns. or that is what I mean by terminal width.)
I'm looking for a way that works with python 2 on linux, but I do appreciate answers that works only with python 3. Thanks!
1 pixel (px) is usually assumed to be 1/96th of an inch. 1 point (pt) is assumed to be 1/72nd of an inch. Therefore 16px = 12pt.
Open the terminal with pressing Ctrl + Alt + T . Then in the General Tab, uncheck Use the system fixed width font, and then select your desired font from dropdown menu.
The digital way to measure font sizes is in pixels. Some word processors such as Microsoft Word still use points as units of measurement for fonts.
body = 62.5% (10px) 1em font size = 10px regardless of font-family. So 1em always equates to the calculated font-size of its parent element, even if you change the font-family.
Maybe. If your terminal software supports XTerm Control Sequences, then the sequence \e[14t
will give you the size width*height in pixels.
Related:
The data structure that stores terminal info in linux is terminfo. This is the structure that any general terminal query would be reading from. It does not contain pixel information, since that is not relevant for the text-only terminals it was designed to specify.
If you're running the code in an X compatible terminal, it is probably possible with control codes, but that would very likely not be portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With