Change Terminal Font Size with C++
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;
UPDATE: With xterm
, this won't work if you're using TrueType fonts. Also, DĂșthomhas suggests in a comment:
I know this is old, but all terminfo strings should be printed using
putp()
[ortputs()
], even in C++.
putp( (std::string{ "\33]50;" } + font_name + "\a").c_str() );
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.