1

I'm creating a c program which colors some text using ANSI escape sequence arguments like printf("\e[38;2;r;g;bm"); in Ubuntu; The problem is that the text get invisible if the background of the console matches with the foreground. If I print a text in black color in a white background it's perfectly visible but when the same code ran on a black background, the text is invisible.

So my plan is to get the terminal background color during runtime and choose text color accordingly.

Is there a way to get the background color of terminal in c?

Mislah
  • 318
  • 1
  • 2
  • 11

1 Answers1

2

ncurses library keeps the windows and terminal data in its own buffers. If you use this library you can read the character and it's attributes. Use function inch or similar

0___________
  • 60,014
  • 4
  • 34
  • 74
  • 1
    The more of this stuff you do, the more you'll wish you're using ncurses, or the more of ncurses you'll have painfully re-written. – tadman Feb 20 '21 at 10:52