如何以像素为单位获取终端大小或字体大小? [英] 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?
(我写等价是因为终端宽度[px] =字体宽度[px]*列数.或者这就是我所说的终端宽度.)
(I wrote equivalently because terminal width[px] = font width[px]*number of columns. or that is what I mean by terminal width.)
我正在寻找一种适用于 linux 上的 python 2 的方法,但我很欣赏仅适用于 python 3 的答案.谢谢!
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!
推荐答案
也许吧.如果您的终端软件支持XTerm Control Sequences,则序列\e[14t
将为您提供以像素为单位的宽度 * 高度大小.
Maybe. If your terminal software supports XTerm Control Sequences, then the sequence \e[14t
will give you the size width*height in pixels.
相关:
- xtermctl - 放置标准shell 参数中的 xterm/dtterm 窗口控制代码,方便使用.请注意,某些终端并不支持所有组合.
- xtermctl - Put standard xterm/dtterm window control codes in shell parameters for easy use. Note that some terminals do not support all combinations.
这篇关于如何以像素为单位获取终端大小或字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!