Hassan Butt
Hassan Butt

Reputation: 51

Is it possible to change Linux Terminal text and background color using C?

I want to change the colour of background UBUNTU TERMINAL with the help of c language .is this possible ?

Upvotes: 2

Views: 1501

Answers (1)

David Ranieri
David Ranieri

Reputation: 41017

You can use escape sequences

printf("\033[37m\033[41m"); // White foreground / Red background
printf("Something\n");
printf("\033[0m");          // Reset

This is the table of colors:

Foreground:

30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White

Background:

40 Black
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White

0 Reset all
1 Bold

Upvotes: 3

Related Questions