Reputation: 891
I am having a similar problem to Ncurses No Output.
Just I am having a getch
call before exiting.
I don't see any output when I don't add a second getch
call
before outputting anything. The following is a collection of
all relevant code parts copied together in one routine
exhibiting the same problem as my complete program.
So some calls look superfluous but I find those necessary
in the local context.
#include <glib.h>
#include <stdlib.h>
#define bool ncbool
#include <ncurses.h>
#undef bool
gint32 main ( gint32 argc, gchar * argv [] )
{
initscr ();
keypad ( stdscr, FALSE );
nonl ();
cbreak ();
nodelay ( stdscr, FALSE );
noecho ();
/*
gint zch_extra;
zch_extra = getch ();
*/
WINDOW* w;
w = newwin ( 5, 10, 3, 3 );
box ( w, 0, 0 );
wnoutrefresh ( w );
mvwaddstr ( w, 1, 1, "huhu" );
wnoutrefresh ( w );
doupdate ();
mvwaddstr ( w, 2, 1, "<cont>" );
wrefresh ( w );
gint zch;
zch = getch ();
clear ();
refresh ();
nl ();
nocbreak ();
echo ();
endwin ();
return 1;
}
I only see output when I add the extra getch
commented out in the code.
Compilation commands:
gcc -I /usr/include/ncurses -I /home/mkiever/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -ansi -ggdb -c -o main.o main.c
gcc -o test main.o -lncurses `pkg-config --libs glib-2.0`
Platform (uname -a
): Linux Pirx 3.16.0-4-686-pae #1 SMP Debian 3.16.7-ckt11-1 (2015-05-24) i686 GNU/Linux
What am I doing wrong? I guess, it's my combination of different refresh
calls, but I don't have a clue where exactly the problem is.
Thanks for taking a look.
Upvotes: 1
Views: 613
Reputation: 54583
curses starts up wanting to clear the screen stdscr (as noted in the manual page for initscr
):
initscr
also causes the first call to refresh(3x) to clear the screen.
Doing that requires a refresh, sometime after the call to initscr
. getch does a refresh of stdscr. In the non-working case, the program creates, modifies and refreshes the other window, but when you call getch, curses refreshes stdscr (again, in the manual), overwriting that window.
It does those steps internally, no need to show the result until the program requests input via getch
.
Upvotes: 1