Change terminal font size using C ++

I am doing a small project for fun in C ++ (on Ubuntu 11.04), and the program is text based (all in the Gnome terminal). I use the ncurses library to change the font color, but I also want to print text with different sizes to the terminal and cannot figure out how to do this with ncurses. Is there a way to do this (maybe with ncurses or with another library)? Ideally, I would like it to be terminal independent, but if it's a solution that only works in Gnome, or only works in Ubuntu, or some other limitation, then this is better than nothing!

Thanks for your help, as always.


I tried Keith Thompson's suggestion, but couldn't get it to work. Here is my code:

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

It simply displays as the same font size specified in the terminal settings. I use: GNOME Terminal 2.32.1 if that helps!

+7
source share
2 answers

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

Here (shortened version) a script I use for this; I call it xfont (the real one has more errors):

 #!/usr/bin/perl use strict; use warnings; print "\e]50;@ARGV\a"; 

I do not know what other terminal emulators recognize this sequence. In particular, I found that it does not work under screen , even if the screen session is in the xterm window.

Please note that you must specify the font name ( "10x20" , "9x15" ), not its size.

EDIT: I have to pay more attention to methods. In C ++, it will be something like:

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

The best you can do is use bold. The terminal emulates a real text terminal, so it does not support different fonts at once.

+1
source

All Articles