0
我有兩個窗口,一個在頂部,一個在底部(我將在後面添加第三個窗口,它們將在這兩個窗口之間)。我爲底部窗口繪製一條水平線,然後開始繪製頂部窗口,並且底部窗口被擦除!當我不想要它時,Ncurses擦除窗口
構造函數display()
被自動調用,而函數displayMessage()
被我的代碼調用。
這裏是display()
代碼:
display::display()
{
//initialize window
initscr(); //start curses mode
cbreak(); //Disable line buffering
curs_set(0); //Don't show curser
refresh(); //Now refresh screen
//setup bottom bar
bottomBar = newwin(2, 80, 22, 0); //create new window
whline(bottomBar, '_', 80); //draw line
wrefresh(bottomBar); //refresh
//setup top bar
topBar = newwin(0, 80, 0, 0); //create new window
wattron(topBar, A_UNDERLINE); //text is to be underlined
}
這裏是displayMessage()
代碼:
void display::displayMessage(string message)
{
//do some other necessary stuff
int length = message.length(); //get length of message
wmove(topBar, 0, 0); //move curser back to beginning
//getch();
wrefresh(topBar); //refresh
//getch();
whline(topBar, '_',80); //draw line for bottom
//getch();
wmove(topBar, 0, 40 - length/2 - 1); //move cursor to center text
wprintw(topBar,message.c_str()); //print message
wrefresh(topBar); //refresh
}
另外這裏是代碼段,調用這兩個:
//initialize stuff
pomodoro instance;
while(true) //loop forever, or until user
{
for (int i = 0; i < 3; i++) //loop thru 4 pomodoros
{
//work
instance.Display.displayMessage("**Time to work!**");
instance.playAlarm();
//waitForUser();
//timer(config.workTime);
//break
return 0; //doing development right now
我忽略了這樣一個小細節! – user3273814