[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Resizing The Terminal Window
From: |
Michael B. Allen |
Subject: |
Resizing The Terminal Window |
Date: |
Sat, 4 Aug 2001 16:58:16 -0400 |
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?).
Thanks,
Mike
--8<--
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <curses.h>
#if HAVE_TERMIOS_H
# include <termios.h>
#else
# include <sgtty.h>
#endif
#if !defined(sun) || !HAVE_TERMIOS_H
# if HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
# endif
#endif
/* This is needed to compile 'struct winsize' */
#if NEED_PTEM_H
#include <sys/stream.h>
#include <sys/ptem.h>
#endif
static int interrupted;
static int waiting;
static void
show_all(void)
{
/*
mvaddch(LINES - 1, COLS - 1, 'X');
refresh();
}
static void
finish(int sig)
{
endwin();
exit(sig != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
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();
}
interrupted = 0;
} else {
interrupted = 1;
}
signal(SIGWINCH, adjust); /* some systems need this */
}
void
init(void)
{
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
}
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;
}
- Resizing The Terminal Window,
Michael B. Allen <=