使用C ++更改终端字体大小 [英] Change Terminal Font Size with C++

查看:701
本文介绍了使用C ++更改终端字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++做一个小项目(在Ubuntu 11.04)和程序是基于文本(所有在Gnome终端)。我使用ncurses库来改变字体颜色,但我也想打印不同大小的文本到终端,而不能弄清楚如何使用ncurses。有没有办法做到这一点(可能与ncurses,或与不同的库)?理想情况下,我希望它是终端无关的,但如果它的解决方案只在Gnome中工作,或只在Ubuntu中工作,或一些其他限制,那样比没有什么!

I'm doing a small project for fun in C++ (in Ubuntu 11.04) and the program is text-based (all in the Gnome terminal). I'm using the ncurses library to change the font color, but I also want to print different sized text to the terminal, and can't figure out how to do that with ncurses. Is there a way to do this (perhaps with ncurses, or with a different library)? Ideally, I'd want it to be terminal-independent,, but if it's a solution that only works in Gnome, or only works in Ubuntu, or some other restriction like that then that's better than nothing!

感谢您的一如既往的帮助。

Thanks for your help as always.

我试过了Keith Thompson的建议但不能让它工作。这是我的代码:

I've tried the suggestion from Keith Thompson but couldn't get it to work. Here's my code:

cout << "\x1b]50;" << "10x20" << "\a" << flush;
cout << "test";

它只显示为在终端首选项中指定的相同字体大小。我使用的是:GNOME Terminal 2.32.1 if that helps!

It just shows up as the same font size specified in the terminal preferences. I'm using: GNOME Terminal 2.32.1 if that helps!

推荐答案

至少 xterm ,可以通过打印转义序列来更改当前字体。语法为 ESCAPE] 50; FONTNAME BEL

At least for xterm, you can change the current font by printing an escape sequence. The syntax is ESCAPE ] 50 ; FONTNAME BEL.

这是我使用的脚本(的缩写版本)我把它叫做 xfont (真正有更多错误检查):

Here's (an abbreviated version of) a script I use for this; I call it xfont (the real one has more error checking):

#!/usr/bin/perl

use strict;
use warnings;

print "\e]50;@ARGV\a";

我不知道哪些终端模拟器识别这个序列。特别是,我发现它不能在屏幕下工作,即使屏幕会话在 xterm 窗口。

I don't know which other terminal emulators recognize this sequence. In particular, I find that it doesn't work under screen, even if the screen session is in an xterm window.

请注意,您必须指定字体的名称 c $ c>10x20,9x15)。

Note that you have to specify the name of the font ("10x20", "9x15"), not its size.

编辑:我应该更多地关注标签。在C ++中,它是这样的:

I should pay more attention to tags. In C++, it would be something like:

std::cout << "\x1b]50;" << font_name << "\a" << std::flush;

这篇关于使用C ++更改终端字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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