Newt components may not display in Red Hat Enterprise Linux 6

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 6
  • newt-0.52.11-3

Issue

  • When the RHEL 6 version of the newt libraries are used, we see that the screens are going blank during the installation. When I replace libnewt.a with the RHEL 5 version and compile my binary, and use the RHEL 5 libnewt.so for linking during runtime, everything works as expected.

Resolution

This issue may occur if newt components are placed directly onto the root window. For components to display properly, the newtForm() function should be used to create a form. Then newtFormAddComponent() and/or newtFormAddComponents() can be used to add components to the form. Finally, newtDrawForm() can be used to display the form.

Root Cause

Newt components should always be added to a form, not placed on the root window. The fact that components would be displayed on the root window is actually a bug with previous version of newt that was fixed in later versions of newt.

Diagnostic Steps

This simple test program demonstrates the problem and its resolution

int main(int argc, char* argv[]) 
{
  int i;                                // Counter variable
  int waittime;                         // Length of time to display form
  newtComponent newt_scale,             // Scale component
    newt_label,                         // A label component
    newt_form;                          // Form component
  int screen_width,                     // Width of the screen
    screen_height;                      // Height of the screen

  char* title_msg = "Waiting...";       // Message to display at the top
  char* label_msg 
    = "Percentage Complete";            // Text for the label


  // If there's a wait time, then use it.  Otherwise just use a default.
  if ( argc > 1 ) {
    waittime = atoi(argv[1]);
  } else {
    waittime = 5;
  }

  if ( waittime ) {
    newtInit();
    newtCls();

    // Determine the screen size so we can place things properly.
    newtGetScreenSize(&screen_width, &screen_height);

    // Draw some text on the root screen.
    newtDrawRootText((screen_width - strlen(title_msg)) / 2, 0, title_msg);

    // Create some components.
    newt_scale = newtScale(10, screen_height/2, screen_width-20, waittime);
    newt_label = newtLabel(10, screen_height/2 + 1, "");

    // Create the form and add the components to the form.
    // WITHOUT THIS STEP, THE COMPONENTS MAY NOT DISPLAY PROPERLY.
    newt_form = newtForm(NULL, NULL, 0);
    newtFormAddComponents(newt_form, newt_scale, newt_label, NULL);
    newtDrawForm(newt_form);

    // Change the text in the label.
    newtLabelSetText(newt_label, label_msg);
    newtRefresh();

    // Wait the specified number of seconds, updating the scale as we go.
    for ( i = 0; i < waittime; i++ ) {
      newtScaleSet(newt_scale, i+1);
      newtRefresh();
      sleep(1);
    }

    // We're finished (yay)!
    newtLabelSetText(newt_label, "Finished!          ");
    newtRefresh();
    sleep(1);
    newtFinished();
  }
}

If lines like the following are omitted:

newt_form = newtForm(NULL, NULL, 0);
newtFormAddComponents(newt_form, newt_scale, newt_label, NULL);
newtDrawForm(newt_form);

the label component may not be displayed. The fact that the scale component may be displayed is acutally a bug that should eventually be fixed.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.