terminal - 使用 python 以编程方式更改 linux 终端中的字体大小
问题描述
在 Ubuntu gnome-terminal 中,可以通过 Ctrl + 或 Ctrl 来完成 - 有没有办法编写一个 python 脚本,在执行时会调整执行它的终端的字体大小?
我需要这个才能使用 timg 在终端中以高分辨率显示图像。
解决方案
检查源(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-size
和increase-font-size
发出信号(参见源代码)。信号代码是您在键盘上使用的代码。但是,您如何从终端仿真器外部开始的脚本确定对象指针尚不清楚。
推荐阅读
- python - 检查字符串中的 id 是否存在于另一个列表中
- angular - 如何以角度获取和显示实时用户通知?
- php - PHP颜色未被确认
- dji-sdk - 在姿态模式下以速度移动无人机
- xml - Ansible - XML 命名空间
- google-apps-script - 获取 Gsuite google drive 上的文件夹列表,在 Google Sheet 上按字母顺序列出
- javascript - 在浏览器中打开新标签的问题
- sql-server - 将 SQL Server 位类型导入 MS Access 数据库
- python - 使用适用于 Python 的 Bot Framework SDK v4 初始化并向 Microsoft Teams 频道发送消息
- windows - 从批处理文件中的变量中删除最后一个字符