Skip to content

Commit

Permalink
LibLine: Never assume a 25x80 terminal
Browse files Browse the repository at this point in the history
Just reuse the lldb hack if the normal stderr ioctl fails for any
reason, and read the size directly off /dev/tty.
  • Loading branch information
alimpfard authored and awesomekling committed Mar 6, 2022
1 parent b05af48 commit 1fcef99
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Userland/Libraries/LibLine/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1fcef99

Please sign in to comment.