diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-02-28 07:31:18 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-06 13:20:41 +0100 |
commit | 1fcef99ff7bd05792e69b64c276c86c277e61f59 (patch) | |
tree | 8bbc78dd297fb27834b112a7ffeba87df58c27f6 /Userland | |
parent | b05af48d80a3d30053c7f381e3bbc5d2517a8865 (diff) | |
download | serenity-1fcef99ff7bd05792e69b64c276c86c277e61f59.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibLine/Editor.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 3863131c10..3a5ce1f420 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -218,22 +218,17 @@ void Editor::ensure_free_lines_from_origin(size_t count) void Editor::get_terminal_size() { struct winsize ws; - - if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) < 0) { - m_num_columns = 80; - m_num_lines = 25; - } else { - if (ws.ws_col == 0 || ws.ws_row == 0) { - // LLDB uses ttys which "work" and then gives us a zero sized - // terminal which is far from useful - if (int fd = open("/dev/tty", O_RDONLY); fd != -1) { - ioctl(fd, TIOCGWINSZ, &ws); - close(fd); - } + ioctl(STDERR_FILENO, TIOCGWINSZ, &ws); + if (ws.ws_col == 0 || ws.ws_row == 0) { + // LLDB uses ttys which "work" and then gives us a zero sized + // 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) |