Ncurses 问题

Ncurses 问题

我尝试制作我的第一个程序,使用ncurses。问题是第一次接触时屏幕就被弄脏了ch = getch();

在此处输入图片描述

在此处输入图片描述

# 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;
}

相关内容