代码之家  ›  专栏  ›  技术社区  ›  Mehdi

使用python在linux终端中以编程方式更改字体大小

  •  0
  • Mehdi  · 技术社区  · 7 年前

    有没有一种方法可以编写一个python脚本,当执行该脚本时,它会调整它所执行的终端的字体大小?

    我需要这个,以便在终端显示图像与高分辨率使用timg。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Thomas Dickey    7 年前

    检查源代码(vte和gnome终端),看起来没有办法做到这一点。其他终端(例如xterm)可以使用转义序列来完成此操作。看见 XTerm Control Sequences :

    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-year old script 这演示了该功能(请参见 fonts.sh ).

    wmctrl 工具(可询问 窗口管理器 与码头谈判)。一些人已经用其他终端实现了这一点,例如, terminology

    职业教育 有一些可以从python脚本访问的代码,使用 g_signal_connect 联想 decrease-font-size increase-font-size 信号(见 source code signal code 就是你正在使用的键盘。但是,如何从终端仿真器外部启动的脚本确定对象指针还不清楚。

        2
  •  0
  •   sohalt    7 年前

    要跨终端实现这一点,没有简单的方法。终端支持所谓的控制序列,它可以设置一系列选项,如文本颜色和其他,但没有用于设置字体大小的控制序列。例如,见 https://en.wikipedia.org/wiki/ANSI_escape_code https://invisible-island.net/xterm/ctlseqs/ctlseqs.html 支持什么样的操作。