Hi,
POSIX 2024 added these two functions in termios.h, tcgetwinsize and
tcsetwinsize. They get and set the terminal size respectively.
As far as I can tell only NetBSD has them implemented [1]. They seem
pretty useful and are easy to implement. I've attached two files that
should work on Linux and BSDs (and any other system with ioctl,
TIOCGWINSZ, TIOCSWINSZ).
Any thoughts on adding them? Windows should be able to support them
too [2]. I just need to define 'struct winsize' in termios.h.
Collin
[1] https://man.netbsd.org/tcgetwinsize.3
[2] https://learn.microsoft.com/en-us/windows/console/console-functions
/* tcsetwinsize.c -- get the size of a terminal window.
Copyright 2024 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Collin Funk. */
#include <config.h>
/* Specification. */
#include <termios.h>
#include <sys/ioctl.h>
int
tcsetwinsize (int fildes, const struct winsize *winsize_p)
{
return ioctl (fildes, TIOCSWINSZ, winsize_p);
}
/* tcgetwinsize.c -- get the size of a terminal window.
Copyright 2024 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* Written by Collin Funk. */
#include <config.h>
/* Specification. */
#include <termios.h>
#include <sys/ioctl.h>
int
tcgetwinsize (int fildes, struct winsize *winsize_p)
{
return ioctl (fildes, TIOCGWINSZ, winsize_p);
}