The ncurses library in C is focused on “low-level” functionalities, if you need a higher level of abstraction check out CDK.

For the popup demo I took model on some “authentication” that consist of 2 modifiable fields (id & password) with the 2 associated labels and 2 buttons at the bottom. The window dispositions schema is at the beginning of the source file. win_menu contains the buttons and win_form the fields/labels. A simple boolean is used to know in which window the cursor is. The popup looks like this :

ncurses popup

And here is the source code :

There is only two interesting functions (beside popup creation/destruction) :

  • driver_buttons() is triggered when a button is pressed, it’s most likely what you want to modify to re-use this example.
  • driver() is tedious but stright-forward, it also does some actions to ease the use. For example if the cursor is on the last field and you press the “down arrow” the cursor will switch to the buttons.

Warning: if the length of your form (label + field) is greater than the length of win_form, post_form() will fail. You can make your popup dynamic in size by re-sizing at runtime your windows according to the length of the form, this is however a bit hack-ish (implementation example here).

This example is very basic and in many cases you will need a more generic popup, you can find an improved version here.