ncurses - resizing glitch
Posted
by
ryyst
on Stack Overflow
See other posts from Stack Overflow
or by ryyst
Published on 2012-12-04T16:14:29Z
Indexed on
2012/12/04
17:05 UTC
Read the original article
Hit count: 247
I'm writing an ncurses
program and am trying to make it respond correctly to terminal resizing. While I can read the terminal dimensions correctly in my program, ncurses
doesn't seem to deal with new dimensions correctly. Here's a (somewhat lengthy) sample program:
#include <ncurses.h>
#include <string.h>
#include <signal.h>
#include <sys/ioctl.h>
void handle_winch(int sig){
struct winsize w;
ioctl(0, TIOCGWINSZ, &w);
COLS = w.ws_col;
LINES = w.ws_row;
wresize(stdscr, LINES, COLS);
clear();
mvprintw(0, 0, "COLS = %d, LINES = %d", COLS, LINES);
for (int i = 0; i < COLS; i++)
mvaddch(1, i, '*');
refresh();
}
int main(int argc, char *argv[]){
initscr();
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = handle_winch;
sigaction(SIGWINCH, &sa, NULL);
while(getch() != 27) {}
endwin();
return 0;
}
If you run it, you can see that the terminal dimensions are correctly retrieved. But the second line, which is supposed to draw *
-characters across the screen, doesn't work. Try resizing the window horizontally to make it larger, the line of *
s will not get larger.
What's the problem here? I'm aware that one can temporarily leave curses mode, but I'd prefer a cleaner solution. Thanks!
© Stack Overflow or respective owner