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;
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() );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With