How to get the terminal size or font size in pixels?

I saw several messages and answers on how to get the size of the terminal in the number of columns and rows. Can I get the size of the terminal, or equivalently, the font size used in the terminal, in pixels?

(I wrote equivalently because the terminal width [px] = font width [px] * number of columns, or this is what I mean by terminal width.)

I am looking for a method that works with python 2 on linux, but I appreciate answers that only work with python 3. Thanks!

+4
source share
4 answers

. XTerm Control Sequences, \e[14t * .

:

+3

ws_xpixel ws_ypixel struct terminfo.

python :

import array, fcntl, termios
buf = array.array('H', [0, 0, 0, 0])
fcntl.ioctl(1, termios.TIOCGWINSZ, buf)
print(buf[2], buf[3])

, 0 0. . VTE .

+2

, , () .

, . TTY - , . , , , .

, .. ? GUI .

+1

A data structure that stores terminal information in Linux, terminfo . This is the structure from which any request with common terminals will be read. It does not contain pixel information, since this does not apply to terminals only for text, which it is intended to indicate.

If you use the code in an X-compatible terminal, it may be possible with control codes, but it will most likely not be portable.

+1
source

Source: https://habr.com/ru/post/1534407/


All Articles