My terminal colors are not restored to their original values in the Nothing Fancy File Manager I am working on. In order to troubleshoot this, I wrote the following:
Code:
#include <stdio.h>
#include <ncurses.h>
#define MAXCOLOR 15
struct textColor{
short red;
short green;
short blue;
}tc[MAXCOLOR], tci[MAXCOLOR];
WINDOW *w;
void set_colors(void)
{
int i;
initscr();
start_color();
use_default_colors();
w=newwin(MAXCOLOR, 150, 0, 0);
for(i=1; i<MAXCOLOR;i++)//store current colors
{
color_content(i, &tci[i].red, &tci[i].green, &tci[i].blue);
init_color(i, tci[i].red, tci[i].green, tci[i].blue);
init_pair(i, i, COLOR_BLACK);
wattrset(w, COLOR_PAIR(i));
wprintw(w, "COLOR %hd\n",i);
wrefresh(w);
}
getchar();
for(i=1; i<MAXCOLOR; i++)//Attempt to restore colors
{
init_color(i, tci[i].red, tci[i].green, tci[i].blue);
wattrset(w, COLOR_PAIR(i));
wprintw(w, "COLOR %hd\n",i);
wrefresh(w);
}
getchar();
endwin();
}
int main(void)
{
set_colors();
return 0;
}
A loop to try to get the current colors, apply those colors (they should be the same), then a second loop just to re-read the stored colors. This is not working. Even the \n in the second loop is not working. In fact The enter key is not even working properly when the program finishes. I have to reboot. Even it I put an ini_pair in the second loop, no luck. I am rather puzzled.