LibC: Implement tc{get,set}winsize

These were added in POSIX issue 8 :^)
This commit is contained in:
2026-05-15 16:51:58 +03:00
parent 05c9f0640c
commit bf2121e166
5 changed files with 31 additions and 21 deletions

View File

@@ -9,8 +9,8 @@
#include <fcntl.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
@@ -141,14 +141,14 @@ void Terminal::run()
m_cells_cols = cols();
{
winsize winsize {
const winsize winsize {
.ws_row = static_cast<unsigned short>(rows()),
.ws_col = static_cast<unsigned short>(cols()),
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
};
if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
perror("ioctl");
if (tcsetwinsize(m_shell_info.pts_master, &winsize) == -1)
perror("tcsetwinsize");
}
{
@@ -212,11 +212,8 @@ void Terminal::run()
.ws_xpixel = static_cast<unsigned short>(m_window->width()),
.ws_ypixel = static_cast<unsigned short>(m_window->height()),
};
if (ioctl(m_shell_info.pts_master, TIOCSWINSZ, &winsize) == -1)
{
perror("ioctl");
return;
}
if (tcsetwinsize(m_shell_info.pts_master, &winsize) == -1)
perror("tcsetwinsize");
});
m_window->set_key_event_callback([&](LibGUI::EventPacket::KeyEvent::event_t event) {

View File

@@ -8,8 +8,8 @@
#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <termios.h>
struct config_t
{
@@ -406,7 +406,7 @@ int main(int argc, const char* argv[])
else for (; i < argc; i++)
MUST(files.emplace_back(BAN::StringView(argv[i])));
g_stdout_terminal = isatty(STDOUT_FILENO) && ioctl(STDOUT_FILENO, TIOCGWINSZ, &g_terminal_size) == 0;
g_stdout_terminal = isatty(STDOUT_FILENO) && tcgetwinsize(STDOUT_FILENO, &g_terminal_size) == 0;
int ret = 0;
for (size_t i = 0; i < files.size(); i++)