0

I have two windows, one at the top, and one at the bottom (and I will be adding a third window later that will be between those two windows). I draw a horizontal line for the bottom window and then I start drawing the top window, and the bottom window gets erased!

The constructor display() is called automatically and than the function displayMessage() is called by my code.

Here is the code for 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

}

Here is the code for 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
}

In addition here is the code snippets that call those two:

//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
  • 198
  • 3
  • 16

1 Answers1

1

This line is a problem:

  topBar = newwin(0, 80, 0, 0); //create new window

because the first parameter is zero. The manual page explains:

If either nlines or ncols is zero, they default to LINES - begin_y and COLS - begin_x.

So the zero-parameter makes your windows overlap (a lot).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105