そのため、コンソール アプリケーションに色を追加するために pdcurses を使用していますが、問題が発生しています。2 番目のウィンドウを作成してその出力に色を付けようとすると、問題なく動作しますが、stdscr に色を付けようとしても何も起こりません。
stdscr は通常どおり stdout に送信する出力を受け取り、コンソールへの C++ スタイルのインターフェイスを使用できるため、別のウィンドウで覆うのではなく、stdscr を使用し続けたいと考えています。出力を cout に送信すると、stdscr に送られます。これが、pdcurses への C++ インターフェイスを使用する方法として現在私が知っている唯一の方法です。さらに、他のライブラリは出力を stdout に直接送信する場合があり、stdscr を使用するとその出力が失われることはありません (print
聞いた上で lua の機能を知っています)。
サンプルコードは次のとおりです。
// This prints a red '>' in the inputLine window properly. //
wattron(inputLine, A_BOLD | COLOR_PAIR(COLOR_RED));
wprintw(inputLine, "\n> ");
wattroff(inputLine, A_BOLD | COLOR_PAIR(COLOR_RED));
// This prints a light grey "Le Testing." to stdscr. Why isn't it red? //
wattron(stdscr, A_BOLD | COLOR_PAIR(COLOR_RED));
cout << "\nLe Testing.\n";
wattroff(stdscr, A_BOLD | COLOR_PAIR(COLOR_RED));
// This does nothing. I have no idea why. //
wattron(stdscr, A_BOLD | COLOR_PAIR(COLOR_RED));
wprintw(stdscr, "\nLe Testing.\n");
wattroff(stdscr, A_BOLD | COLOR_PAIR(COLOR_RED));
pdcurses を初期化する方法は次のとおりです。
// Open the output log which will mimic stdout. //
if (userPath)
{
string filename = string(userPath) + LOG_FILENAME;
log.open(filename.c_str());
}
// Initialize the pdCurses screen. //
initscr();
// Resize the stdout screen and create a line for input. //
resize_window(stdscr, LINES - 1, COLS);
inputLine = newwin(1, COLS, LINES - 1, 0);
// Initialize colors. //
if (has_colors())
{
start_color();
for (int i = 1; i <= COLOR_WHITE; ++i)
{
init_pair(i, i, COLOR_BLACK);
}
}
else
{
cout << "Terminal cannot print colors.\n";
if (log.is_open())
log << "Terminal cannot print colors.\n";
}
scrollok(stdscr, true);
scrollok(inputLine, true);
leaveok(stdscr, true);
leaveok(inputLine, true);
nodelay(inputLine, true);
cbreak();
noecho();
keypad(inputLine, true);
私は何を間違っていますか?