AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 868745
Accepted
don.joey
don.joey
Asked: 2017-01-07 06:58:27 +0800 CST2017-01-07 06:58:27 +0800 CST 2017-01-07 06:58:27 +0800 CST

如何在终端配置更改字体大小的步骤?

  • 772

如何在终端配置更改字体大小的步骤?我现在使用 10pt,下一步使用键盘快捷键太大了。如何配置步长?

command-line
  • 1 1 个回答
  • 262 Views

1 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2017-01-08T05:17:51+08:002017-01-08T05:17:51+08:00

    下面的脚本将一次设置所有配置文件的字体大小,步长为 0.5。你必须看看这对你来说是否足够;终端不会对所有步骤做出反应。

    就我而言,从

    10 --> 10.5 --> 11
    

    10.5

    在此处输入图像描述

    11

    在此处输入图像描述

    但随后从

    11 --> 11.5
    

    直到再次增加到

    12

    在此处输入图像描述

    这可能与字体大小有关,与窗口大小有关,因为您在终端中使用的是单型字体,所以它不允许浮动。

    然而,该脚本提供了在这种情况下存在的大小。

    剧本

    #!/usr/bin/env python3
    import subprocess
    import sys
    import ast
    
    """
    Copyright (C) 2016  Jacob Vlijm
    https://launchpad.net/~vlijm/+contactuser
    This program is free software: you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free Software
    Foundation, either version 3 of the License, or any later version. This
    program is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
    A PARTICULAR PURPOSE. See the GNU General Public License for more details. You
    should have received a copy of the GNU General Public License along with this
    program.  If not, see <http://www.gnu.org/licenses/>.
    """
    
    arg = sys.argv[1]
    
    k = ["/org/gnome/terminal/legacy/profiles:/:", "/use-system-font", "font"]
    
    def get(cmd):
        return subprocess.check_output(cmd).decode("utf-8").strip()
    
    def run(cmd):
        subprocess.Popen(cmd)
    
    def set_size(profile):
        def_font = k[0]+profile+k[1]
        # first set use default font to false
        run(["dconf", "write", def_font, "false"])
        # read the current font
        currfont = ast.literal_eval(get(["dconf", "read", k[0]+profile+"/"+k[2]])).split()
        # read the current size
        currsize = float(currfont[-1])
        # set the newsize
        if arg == "up":
            newsize = currsize+0.5
        elif arg == "down":
            newsize = currsize-0.5
        run(["dconf", "write", k[0]+profile+"/"+k[2], "'"+currfont[0]+" "+str(newsize)+"'"])
    
    # get profiles
    prf = k[0][:-1]+"list"
    # set fontsize up/down 0.5
    for p in ast.literal_eval(get(["dconf", "read", prf])):
        set_size(p)
    

    如何使用

    1. 将脚本复制到一个空文件中,另存为terminalfont.py
    2. 通过以下命令测试运行脚本:

      python3 /path/to/terminalfont.py up
      

      增加字体大小,以及

      python3 /path/to/terminalfont.py down
      

      减小字体大小

    3. 如果一切正常,将两个命令添加到快捷方式

    解释

    不幸的是,没有可gsettings用于设置终端字体大小的键。我们需要dconf直接使用来读取和编辑设置。

    我们可以先通过以下命令获取配置文件列表:

    dconf read /org/gnome/terminal/legacy/profiles:/list
    

    一旦我们有了配置文件列表,脚本就会首先禁用默认字体(每个配置文件):

    dconf write /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/use-system-font false
    

    b1dcc9dd-5262-4d8d-a863-c897e6d979b9个人资料的 ID在哪里

    随后我们使用以下命令读取当前字体和大小:

    dconf read /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/font
    

    ...我们解析字体大小,添加或减去0.5,并通过以下方式设置新大小:

    dconf write /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/font 'Monospace 14.0'
    

    笔记

    如前所述,如果这对您来说足够了,则只能由您进行测试。但是,如果没有,恐怕我们无法修复它,因为字体大小必须与单字体的终端窗口成一定比例。

    • 4

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve