当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - Change Terminal Font Size with C++

问题描述:

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.


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";

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!

网友答案:

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

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";

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.

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

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

std::cout << "\x1b]50;" << font_name << "\a" << std::flush;
网友答案:

The best you can do is to use bold font. Terminal emulates real text-based terminal so it doesn't support different fonts at once.

分享给朋友:
您可能感兴趣的文章:
随机阅读: