1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-24 16:22:11 +00:00

LibLine: Never assume a 25x80 terminal

Just reuse the lldb hack if the normal stderr ioctl fails for any
reason, and read the size directly off /dev/tty.
This commit is contained in:
Ali Mohammad Pur 2022-02-28 07:31:18 +03:30 committed by Andreas Kling
parent b05af48d80
commit 1fcef99ff7

View file

@ -218,22 +218,17 @@ void Editor::ensure_free_lines_from_origin(size_t count)
void Editor::get_terminal_size() void Editor::get_terminal_size()
{ {
struct winsize ws; struct winsize ws;
ioctl(STDERR_FILENO, TIOCGWINSZ, &ws);
if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) < 0) { if (ws.ws_col == 0 || ws.ws_row == 0) {
m_num_columns = 80; // LLDB uses ttys which "work" and then gives us a zero sized
m_num_lines = 25; // terminal which is far from useful
} else { if (int fd = open("/dev/tty", O_RDONLY); fd != -1) {
if (ws.ws_col == 0 || ws.ws_row == 0) { ioctl(fd, TIOCGWINSZ, &ws);
// LLDB uses ttys which "work" and then gives us a zero sized close(fd);
// terminal which is far from useful
if (int fd = open("/dev/tty", O_RDONLY); fd != -1) {
ioctl(fd, TIOCGWINSZ, &ws);
close(fd);
}
} }
m_num_columns = ws.ws_col;
m_num_lines = ws.ws_row;
} }
m_num_columns = ws.ws_col;
m_num_lines = ws.ws_row;
} }
void Editor::add_to_history(String const& line) void Editor::add_to_history(String const& line)