0

I am trying to get a simple console program to work in windows (it works in linux). I uses curses on linux, and when moving to windows I found that the least troublesome way port my program was to use pdcurses. I have used pdcurses before in windows, but with the win32a addon. However, I would like this program to run inside the windows console.

The problem is that it just seems to completely ignore all color commands. Is this a problem with pdcurses on windows or am I just being stupid? Even the demos that come with the package don't have color. I am using MSVC++ express 2010 on Win7 64x.

hasColors() returns TRUE. When Ii run this simple example from the documentation, everything is still in black and white:

#include <curses.h>

int main()

{
    initscr();

    if(has_colors() == FALSE)
    {   endwin();
        printf("Your terminal does not support color\n");
        exit(1);
    }
    start_color();

    init_pair(1, COLOR_BLACK, COLOR_RED);
    init_pair(2, COLOR_BLACK, COLOR_GREEN);

    attron(COLOR_PAIR(1));
    printw("This should be printed in black with a red background!\n");

    attron(COLOR_PAIR(2));
    printw("And this in a green background!\n");
    refresh();


    endwin();
}
4

2 回答 2

0

你是不是错过了:

attroff(COLOR_PAIR(1)) attroff(COLOR_PAIR(2))

每次打印后?

添加它们,看看会发生什么。

我在 x64 win7 下使用带有 code::blocks 的 pdcurses,我对颜色没有任何问题。有可能只有 MSVC++ 有这个问题,但我对此表示怀疑。

于 2013-12-10T18:59:34.090 回答
0

它可能无法解决任何问题,但我发现有时程序不会更新 GCC 代码块上的颜色,我添加了一个 getch(); 最后,它似乎解决了我在颜色或在屏幕上添加文本时遇到的任何问题。

确保 getch(); 虽然是在刷新之前

于 2013-11-29T03:18:46.947 回答