summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2021-04-17 22:00:03 +0430
committerLinus Groh <mail@linusgroh.de>2021-04-17 22:10:35 +0200
commitfb80d5adda02028468100a6f91e82b2a64672ac5 (patch)
tree3a59251b4b2fcbd872e938f8d0ce6f4411db8f5d /Userland
parentb58dbc29fc8b1e5711a8548f8dc2fc66c77b5213 (diff)
downloadserenity-fb80d5adda02028468100a6f91e82b2a64672ac5.zip
LibLine: Check the terminal size at the start of get_line()
There are cases where the line editor could miss the WINCH signal (e.g. in the shell, while another program is in the foreground), This patch makes it so that LibLine notices the change in terminal size in such cases.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibLine/Editor.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp
index e86d08bff0..d66cfde642 100644
--- a/Userland/Libraries/LibLine/Editor.cpp
+++ b/Userland/Libraries/LibLine/Editor.cpp
@@ -208,6 +208,7 @@ Editor::~Editor()
void Editor::get_terminal_size()
{
struct winsize ws;
+
if (ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) < 0) {
m_num_columns = 80;
m_num_lines = 25;
@@ -502,8 +503,8 @@ void Editor::initialize()
struct termios termios;
tcgetattr(0, &termios);
m_default_termios = termios; // grab a copy to restore
- if (m_was_resized)
- get_terminal_size();
+
+ get_terminal_size();
if (m_configuration.operation_mode == Configuration::Unset) {
auto istty = isatty(STDIN_FILENO) && isatty(STDERR_FILENO);
@@ -629,6 +630,13 @@ auto Editor::get_line(const String& prompt) -> Result<String, Editor::Error>
return Error::ReadFailure;
}
+ auto old_cols = m_num_columns;
+ auto old_lines = m_num_lines;
+ get_terminal_size();
+
+ if (m_num_columns != old_cols || m_num_lines != old_lines)
+ m_refresh_needed = true;
+
set_prompt(prompt);
reset();
strip_styles(true);