I have a global variable called g_data that holds a pointer to a structure which contains, among many, two variables to hold the height and width of the terminal. The function signalhandler below checks whether the terminal has been resized. In that case, the function update_data changes the values of those two variables to the current height and width of the terminal.
My problem is that the function tgetnum, whenever it's being called, it doesn't seem to get the current terminal size (after the resizing).
I'm using Ubuntu 18.04LTS
typedef struct s_data
{
t_lst *lst;
t_ldim ldim;
t_pos pos;
int height;
int width;
int max;
int lstsize;
} t_data;
int i = 0;
void signalhandler(int sig)
{
if (sig == SIGWINCH)
{
update_data(g_data);
if (g_data == NULL)
exit(EXIT_FAILURE);
enable_cap("ti");
print_args(g_data);
printf("%d - %d\n", i++, tgetnum("co"));
signal(SIGWINCH, signalhandler);
}
else if (sig == SIGTSTP)
{
signal(SIGTSTP, SIG_DFL);
modify_main_caps(SET);
enable_cap("te");
ioctl(0, TIOCSTI, "\032");
}
else if (sig == SIGCONT)
{
signal(SIGTSTP, signalhandler);
modify_main_caps(UNSET);
update_data(g_data);
enable_cap("ti");
print_args(g_data);
}
}
Looking up
tgetnumin Linux man pages, it says:Looking up terminfo in man, it says:
Because it is a database, there is no dynamic updating. It only gets the statically defined information from the database for your current terminal.
Update:
Googling around I found http://man7.org/tlpi/code/online/dist/tty/demo_SIGWINCH.c.html which sets a
SIGWINCHhandler and then usesioctlto get the updated size, roughly: