How to get terminal size or font size in pixels?

后端 未结 4 1868
执念已碎
执念已碎 2021-01-13 03:58

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

4条回答
  •  别那么骄傲
    2021-01-13 04:16

    Another possible approach, with limited support, is checking the ws_xpixel and ws_ypixel values of struct terminfo.

    A python snippet to query these values:

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

    This only works in certain terminal emulators, others always report 0 0. See e.g. the VTE feature request to set these fields for a support matrix.

提交回复
热议问题