Fallback to 80x24 terminal size when ioctl fails or returns 0x0

Fixes #4286
This commit is contained in:
Maxime Coste 2021-08-04 20:47:04 +10:00
parent 1b7616b3fc
commit 7b126704c7

View File

@ -580,9 +580,9 @@ void TerminalUI::check_resize(bool force)
return; return;
auto close_fd = on_scope_end([fd]{ ::close(fd); }); auto close_fd = on_scope_end([fd]{ ::close(fd); });
winsize ws; DisplayCoord terminal_size{24_line, 80_col};
if (::ioctl(fd, TIOCGWINSZ, &ws) != 0) if (winsize ws; ioctl(fd, TIOCGWINSZ, &ws) == 0 and ws.ws_row > 0 and ws.ws_col > 0)
return; terminal_size = {ws.ws_row, ws.ws_col};
const bool info = (bool)m_info; const bool info = (bool)m_info;
const bool menu = (bool)m_menu; const bool menu = (bool)m_menu;
@ -590,12 +590,12 @@ void TerminalUI::check_resize(bool force)
if (info) m_info.destroy(); if (info) m_info.destroy();
if (menu) m_menu.destroy(); if (menu) m_menu.destroy();
m_window.create({0, 0}, {ws.ws_row, ws.ws_col}); m_window.create({0, 0}, terminal_size);
m_screen.create({0, 0}, {ws.ws_row, ws.ws_col}); m_screen.create({0, 0}, terminal_size);
m_screen.hashes.clear(); m_screen.hashes.clear();
kak_assert(m_window); 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")) // if (char* csr = tigetstr((char*)"csr"))
// putp(tparm(csr, 0, ws.ws_row)); // putp(tparm(csr, 0, ws.ws_row));