From 7b126704c750bf92b18a5b838e25b381516ddb4a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 4 Aug 2021 20:47:04 +1000 Subject: [PATCH] Fallback to 80x24 terminal size when ioctl fails or returns 0x0 Fixes #4286 --- src/terminal_ui.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc index bb48ad61..029fd8eb 100644 --- a/src/terminal_ui.cc +++ b/src/terminal_ui.cc @@ -580,9 +580,9 @@ void TerminalUI::check_resize(bool force) return; auto close_fd = on_scope_end([fd]{ ::close(fd); }); - winsize ws; - if (::ioctl(fd, TIOCGWINSZ, &ws) != 0) - return; + DisplayCoord terminal_size{24_line, 80_col}; + if (winsize ws; ioctl(fd, TIOCGWINSZ, &ws) == 0 and ws.ws_row > 0 and ws.ws_col > 0) + terminal_size = {ws.ws_row, ws.ws_col}; const bool info = (bool)m_info; const bool menu = (bool)m_menu; @@ -590,12 +590,12 @@ void TerminalUI::check_resize(bool force) if (info) m_info.destroy(); if (menu) m_menu.destroy(); - m_window.create({0, 0}, {ws.ws_row, ws.ws_col}); - m_screen.create({0, 0}, {ws.ws_row, ws.ws_col}); + m_window.create({0, 0}, terminal_size); + m_screen.create({0, 0}, terminal_size); m_screen.hashes.clear(); kak_assert(m_window); - m_dimensions = DisplayCoord{ws.ws_row-1, ws.ws_col}; + m_dimensions = terminal_size - 1_line; // if (char* csr = tigetstr((char*)"csr")) // putp(tparm(csr, 0, ws.ws_row));