ncurses不会改变字体大小,但可以使用视频属性(加粗、斜体)来操作字体中的样式。一些终端有一种文档化的方法来改变它们的字体大小,这会影响整个窗口(使其对ncurses“不可见”)。
如上所述,xterm具有设置字体的功能,该功能在XTerm控制序列中有记录,在操作系统命令部分中:
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).
The same rule (plus or minus sign, optional number) is used
when querying the font. The remainder of Pt is ignored.
A font can be specified after a "#" index expression, by
adding a space and then the font specifier.
If the TrueType Fonts menu entry is set (the renderFont
resource), then this control sets/queries the faceName
resource.
手册页面将
faceName文档化为字体系列名称。虽然可以尝试向其中添加
pixelsize属性,但可能不起作用。但是更改
faceName可以解决问题(假设您已选择了TrueType字体),例如,在我的当前计算机上使用此脚本:
#!/bin/bash
setfont() {
read -p "$1:"
printf '\033]50;%s\007' "$1"
read -p "done!"
}
setfont "Bitstream Charter"
setfont "URW Gothic L"
我使用fc-list
获取了这些字体名称。类似的脚本也可以用于位图字体,使用xlsfonts
找到的名称。对于位图字体,有一些字体别名,例如9x15
、10x20
、12x24
,但这些仅针对xlsfonts
的数千个结果中的少数组合进行定义。关于此,请阅读X Logical Font Description Conventions文档。顺便说一句,这些有用的字体别名没有在任何地方系统地记录。
这只会改变字符的外观,可能不会改变大小。但是,通过阅读文档,可以使用从rxvt适应的功能,使用数字逐步浏览字体菜单上的设置。对我来说,这个脚本很有效,将字体更改为上一个,两次,下两个(返回默认值),上四个(到达设置的末尾),然后返回:
#!/bin/bash
changesize() {
read -p "$1:"
printf '\033]50;#%s\007' "$1"
read -p "done!"
}
changesize +1
changesize +1
changesize -2
changesize +4
changesize -4
由于使用了一个不在终端数据库中的控制序列,因此程序中的 cout
或 printf
是合适的。 对于来自终端数据库的字符串,应该使用putp
,因为它们可能包含填充信息,这些信息会被 putp
解释(当直接打印到终端时将没有用处)。 相反,某些随机的控制序列可能看起来像是可能会使putp
混淆的东西。
填充已在terminfo(5)
中记录。