mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
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.
This commit is contained in:
parent
b58dbc29fc
commit
fb80d5adda
Notes:
sideshowbarker
2024-07-18 19:29:36 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/fb80d5adda0 Pull-request: https://github.com/SerenityOS/serenity/pull/6419 Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user