首页 > 解决方案 > 使用 python 以编程方式更改 linux 终端中的字体大小

问题描述

在 Ubuntu gnome-terminal 中,可以通过 Ctrl + 或 Ctrl 来完成 - 有没有办法编写一个 python 脚本,在执行时会调整执行它的终端的字体大小?

我需要这个才能使用 timg 在终端中以高分辨率显示图像。

标签: terminalgnome-terminal

解决方案


检查源(vte 和 gnome-terminal),看起来没有办法做到这一点。其他终端(例如,xterm)可以使用转义序列来做到这一点。请参阅XTerm 控制序列

OSC Ps ; Pt ST
          Set Text Parameters.  For colors and font, if Pt is a "?", the
          control sequence elicits a response which consists of the con-
          trol sequence which would set the corresponding value.  The
          dtterm control sequences allow you to determine the icon name
          and window title.

  ...

            Ps = 5 0  -> Set Font to Pt.  These controls may be disabled
          using the allowFontOps resource.  If Pt begins with a "#",
          index in the font menu, relative (if the next character is a
          plus or minus sign) or absolute.  A number is expected but not
          required after the sign (the default is the current entry for
          relative, zero for absolute indexing).

vte 可以识别50,但是(就像许多其他 xterm 功能一样)只是一个不做任何事情的存根。xterm 源代码包括一个20 年前的脚本,用于演示该功能(请参阅 参考资料fonts.sh)。

而不是使用转义序列,您也许可以使用该wmctrl工具(它可以要求窗口管理器与终端协商)。有些人已经用其他终端做到了这一点,例如,术语(但最终使用转义序列)。

vte确实有一些可以从 python 脚本访问的代码,g_signal_connect用于关联 decrease-font-sizeincrease-font-size发出信号(参见源代码)。信号代码是您在键盘上使用的代码。但是,您如何从终端仿真器外部开始的脚本确定对象指针尚不清楚。


推荐阅读