如果可以像使用CSS一样在终端中动态更改字体 [英] If you can dynamically change the font in the terminal like you can with CSS

查看:91
本文介绍了如果可以像使用CSS一样在终端中动态更改字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了两个问题:

I have seen these two questions:

  • Can I change the font of terminal?
  • Is it possible to show mathematical symbols in the terminal?

答案都是肯定的。

我想知道是否可以使用CLI从自定义字体将数学符号打印到终端中,只有它是个人使用的,而与此同时,我不必在终端上更改字体(我可以继续将默认字体用于其他所有内容)。也就是说,假设我将终端的默认字体设置为 x 。 CLI程序将已下载并具有字体 y 的本地副本。然后,CLI将终端的字体类型设置为字体 y ,以字体 y 绘制一些内容,然后进行设置在关闭之前,将其恢复为字体 x 。这样,终端仍然具有其原始字体,但它也能够显示另一种字体的符号(如数学符号)。

I am wondering if it is possible to have a CLI print out mathematical symbols into the terminal from a custom font only it is personally using, while at the same time I never have to change the font on my terminal (I can keep using the default font for everything else). That is, say I have my default font for my terminal set to x. The CLI program would have downloaded and have a local copy of font y. Then the CLI sets the font type to font y for the terminal, draws some stuff in font y, and then sets it back to font x before closing. That way the terminal still has its original font but it was also able to display symbols (like math symbols) from another font. Wondering if this is in any way possible.

我正在想象这种感觉,就像您在CSS中拥有字体家族一样。在CSS中,您可以向最终用户的浏览器提供下载的字体,以使用与浏览器默认字体不同的字体显示文本。想知道您是否可以使用终端执行相同的操作。具体来说,我在Mac上使用iTerm2,但是知道是否可能在那里或在任何其他终端上很有用。

I'm imagining this sort of like how you have font-families in CSS. In CSS, you can provide a downloaded font to the end user's browser to display the text using a different font than what they have as the default in the browser. Wondering if you can do this same sort of thing with the terminal. Specifically I am on the Mac using iTerm2, but knowing if it's possible there or on any other terminal would be useful to know.

推荐答案

不是。原则上,您可以使用ANSI转义码 ESC [11m 切换字体,其中11可以是介于10到20之间的任何字体,默认值为10。您必须先加载适当的字体( setfont ?)。

Not really. In principle you can switch fonts with the ANSI escape code ESC [ 11m where 11 can be any of the "fonts" between 10 and 20 inclusive with 10 being the default. You would have to load an appropriate font first (setfont?).

实际上,没有任何终端仿真器实际支持此字体。 (我听说pangoterm确实如此。)

In practice no terminal emulator actually supports this (I've heard that pangoterm does).

通常的解决方法是创建修补的Unicode字体,该字体在私人使用区域中编码其他符号,并配置终端模拟器使用该字体。但是,您的程序随后必须输出正确的代码点,您无法在本地将ASCII字体切换。字体修补例如由Powerline vim扩展程序建议。

The usual workaround is to create a patched Unicode font that encodes additional symbols in private-use areas, and configure your terminal emulator to use that font. However, your programs would then have to output the correct codepoints, you can't locally switch the font for ASCII. Font patching is e.g. suggested by the Powerline vim extension.

这篇关于如果可以像使用CSS一样在终端中动态更改字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆