Boying Boying - 1 year ago 151
C++ Question

How to popup a ncurses widget without clearing background?

The ncurses normally clears background and show widgets/windows.

I would like to make ncurses working like a helper for current session and it pops up window above current ssh session

The appearance will be look like the CMD.exe implementation (see picture)

enter image description here

Answer Source

Short answer: you cannot do this.

Long: curses applications are full-screen programs that clear the screen so that they know what is on the screen (so the curses library can optimize its output: use the least amount of work).

You could write a low-level application which uses its own rules, e.g., using the terminfo/termcap interface. Even if you link it with the ncurses library, that would not make it a curses application, but a terminfo (preferred) or termcap (long deprecated) application. See the ncurses FAQ Types of library users.

To make a terminfo application for the example shown, your application would (offhand, there are probably additional things to do):

  • initialize the terminal (actually the application's connection to the terminal database) using setupterm.
  • if the terminal supports it, save the original cursor position
  • clear the remainder of the screen
  • draw your dialog
  • run your dialog
  • using the saved cursor position, return the cursor to the original position
  • clear the remainder of the screen.

Depending on the terminal's capabilities, different schemes (different combinations of terminal capabilities) may be needed to clear the screen, draw the dialog, etc.

In drawing the dialog, you wouldn't be able to use any of the high-level curses calls. The python documentation does not really outline the low-level calls. To see that, read the ncurses documentation.

Some may suggest alternatives (I won't), but those have the same limitations which are due to the terminal capabilities.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download