Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get terminal size or font size in pixels?

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!

like image 493
Yosh Avatar asked Apr 01 '14 10:04

Yosh


People also ask

How do you calculate font size in pixels?

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.

How do I change font size in Terminal?

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.

Are font sizes in pixels?

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.

How do you calculate type size?

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.


2 Answers

Maybe. If your terminal software supports XTerm Control Sequences, then the sequence \e[14t will give you the size width*height in pixels.

Related:

  • xtermctl - Put standard xterm/dtterm window control codes in shell parameters for easy use. Note that some terminals do not support all combinations.
like image 122
Aaron Digulla Avatar answered Sep 20 '22 10:09

Aaron Digulla


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.

like image 32
slongfield Avatar answered Sep 20 '22 10:09

slongfield