bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resizing The Terminal Window


From: Michael B. Allen
Subject: Re: Resizing The Terminal Window
Date: Sat, 4 Aug 2001 21:01:10 -0400

On Sat, Aug 04, 2001 at 06:23:16PM -0400, Thomas Dickey wrote:
> On Sat, Aug 04, 2001 at 04:58:16PM -0400, Michael B. Allen wrote:
> > I'm trying to hone the resizing process so I've written a minimal
> > application derived from test/view.c to illustrate it. I have been
> > stuggling to find information on the topic so I would greatly appriciate
> > it if you could verify that the below code is indeed optimal and portable
> > (e.g. are all the conditional includes necessary?).
> 
> well, in view.c I keep in mind that POSIX says I can't do buffered I/O
> in a signal handler.  That's a portability gotcha that has bitten me
> a couple of times (the library doesn't do this, but the example does).
> The endwin() call would be buffered, and there's a possibility that the
> program would break.

Isn't calling show_all from a signal handler potentially bad for similar
reasons?

Mike

static void
adjust(int sig)
{
        if (waiting || sig == 0) {
                struct winsize size;

                if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { 
                        resizeterm(size.ws_row, size.ws_col);
                        wrefresh(curscr);   /* Linux needs this */ 
                        show_all(); /* <---- could SIGWINCH call this? */
                }
                interrupted = 0;
        } else {
                interrupted = 1; 
        }
        signal(SIGWINCH, adjust);    /* some systems need this */ 
}
int
main(int argc, char *argv[])
{
        int c;

        signal(SIGINT, finish);
        signal(SIGWINCH, adjust);
        init();
        show_all();

        for (;;) {
                if (interrupted) {
                        adjust(0);
                }
                waiting = 1;
                c = getch();
                waiting = 0;

                if (c == 'q') {
                        finish(EXIT_SUCCESS);
                }
        }
        return EXIT_FAILURE;
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]