1

I try to make my first program which use ncurses. The problem is that screen got clean when it meet first time ch = getch();

enter image description here

enter image description here

# include "sys/ioctl.h"
# include "ncurses.h"
# include "unistd.h"

int main()
{
    WINDOW *win;
    bool listOn = false, running = true, exit = false;
    unsigned int hightlighted = 0, middleX, middleY, ch;


// init screen
initscr();
noecho();
cbreak();

// init color module
start_color();

// init colors

// selected color
init_pair(1, COLOR_BLACK, COLOR_CYAN);
// active color
init_pair(2, COLOR_BLACK, COLOR_YELLOW);

winsize term;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &term);
win = newwin(term.ws_row, term.ws_col, 0, 0);
middleX = term.ws_col / 2;
middleY = term.ws_row / 2;
keypad(win, TRUE);
curs_set(0);

while(running){
    if(!listOn){
        mvprintw(middleY - 1, middleX - 12, "Circular Linked List v1.0");
        if(!exit) attron(COLOR_PAIR(1));
        mvprintw(middleY, middleX - 6, "Make new list");
        if(!exit) attroff(COLOR_PAIR(1));
        if(exit) attron(COLOR_PAIR(1));
        mvprintw(middleY + 1, middleX - 2, "Close");
        if(exit) attroff(COLOR_PAIR(1));
        move(0, 0);
        refresh();

        ch = wgetch(win);
        if(ch == KEY_UP){
            exit = false;
        }
        else if(ch == KEY_DOWN){
            exit = true;
        }

    }else{
        running = false;
    }
}

// restore initial terminal settings
endwin();

return 0;
}
1

0

You must log in to answer this question.

Browse other questions tagged .