Skip to main content
Welcome guest. | Register | Login | Post

[probably solved] ncurses ERR instead of KEY_RESIZE

6 replies [Last post]
tbuitenh's picture
Joined: 2005-12-21

I'm writing a little app with ncurses, and I have a really strange problem. When I resize the terminal window, I don't get KEY_RESIZE but ERR. Also, when pretending the ERR is actually a KEY_RESIZE, I can't make the screen redraw.

Anyone have an idea what's up?

By the way it's called "faith" because I'm writing a replacement for the "qed" editor Smiling

If for some crazy reason you want to reuse or redistribute (parts of) this program, please use a GPL license, version 2 or newer.

tbuitenh's picture
Joined: 2005-12-21
If someone using something

If someone using something else than archlinux wants to build and test this for me:

gcc -c faith.c
gcc -o faith -lncurses faith.o

When you hit some random keys, it should display their (octal) keycodes. Escape will make it quit. But what happens when you resize the xterm? And what if you replace

if (inp == KEY_RESIZE || inp == ERR) faith_resize_screen();


if (inp == KEY_RESIZE) faith_resize_screen();

and then recompile?

tbuitenh's picture
Joined: 2005-12-21
simplified it
#include <ncurses.h>

int main(void) {
  WINDOW * stdscr = initscr();
  int width, height;
  while (1) {
    getmaxyx(stdscr, height, width);
    mvprintw(0,0,"%d %d %o\n", height, width, getch());
  return 0;

Even that simple program gets ERR (37777777777) when resizing, and the height and width don't change. Is there a problem with my ncurses, or am I doing something wrong?

tbuitenh's picture
Joined: 2005-12-21
I found out the ncurses in

I found out the ncurses in archlinux is compiled without --enable-sigwinch , but that's not the problem (I rebuilt ncurses with that configure option, and the problem is still there).

Writing my own SIGWINCH handler could be a solution, though.

dylunio's picture
Joined: 2005-12-20
I've just compiled the

I've just compiled the program on Gentoo. The output of gcc -v is:

Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.1.1-r1/work/gcc-4.1.1/configure --prefix=/usr
--bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.1 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include 
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4 --host=i686-pc-linux-gnu 
--build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib 
--disable-checking --disable-werror --disable-libunwind-exceptions --disable-multilib --disable-libmudflap 
--disable-libssp --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix 
--enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.1.1 (Gentoo 4.1.1-r1)

As for your questions:
with "if (inp == KEY_RESIZE || inp == ERR) faith_resize_screen();" I get the octal codes for the keys, but when I resize the xterm the ncurses window doesn't resize.

with "if (inp == KEY_RESIZE) faith_resize_screen();" I get the octal codes for the keys, and ERR when I resize the xterm, the ncurses window doesn't seem to resize.


tbuitenh's picture
Joined: 2005-12-21
Then obviously I'm doing

Then obviously I'm doing something (or forgetting to do it?) that makes the screen not resizable. I need to find an example somewhere...

tbuitenh's picture
Joined: 2005-12-21
problem found!

from the manual page of resizeterm (which appears to be the default SIGWINCH handler in ncurses:


If the environment variables LINES or COLUMNS are set, this overrides the library's use of the window size obtained from the operating system. Thus, even if a SIGWINCH is received, no screen size change may be recorded. In that case, no KEY_RESIZE is queued for the next call to getch; an ERR will be returned instead.

And guess what?

/home/taco/faith $ echo $LINES $COLUMNS
20 70

So the solution is to do almost the same for ERR as for KEY_RESIZE: fetch the screen size, and redraw the screen. The only difference is that it should be fetched from these environment variables instead of getmaxyx(). I guess I'll write a function faith_getmaxyx() to replace all the calls to getmaxyx().

By the way, I removed the original program from the attachment, because I don't want search engines to pick up my poor code Smiling .

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.