diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-07-06 19:58:11 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-06 22:39:32 +0200 |
commit | 5fedf90bf9e19ea2d46e62af465992f8c8e37b30 (patch) | |
tree | 1d12e7f701f1afdaad4b3089b7c7f10635406b30 /Libraries | |
parent | 06d50f64b0b67fd94854b6c9f85f29ab3b0b38e5 (diff) | |
download | serenity-5fedf90bf9e19ea2d46e62af465992f8c8e37b30.zip |
LibLine: Avoid refreshing the display when resizing
This allows was_resized() to be called while the editor is not active
(i.e. get_line() is not in frame).
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibLine/Editor.cpp | 39 | ||||
-rw-r--r-- | Libraries/LibLine/Editor.h | 7 |
2 files changed, 23 insertions, 23 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 48226094af..665c2dc73f 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -48,6 +48,18 @@ Editor::Editor(Configuration configuration) { m_always_refresh = configuration.refresh_behaviour == Configuration::RefreshBehaviour::Eager; m_pending_chars = ByteBuffer::create_uninitialized(0); + get_terminal_size(); + m_suggestion_display = make<XtermSuggestionDisplay>(m_num_lines, m_num_columns, m_cached_prompt_metrics); +} + +Editor::~Editor() +{ + if (m_initialized) + restore(); +} + +void Editor::get_terminal_size() +{ struct winsize ws; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) { m_num_columns = 80; @@ -56,13 +68,6 @@ Editor::Editor(Configuration configuration) m_num_columns = ws.ws_col; m_num_lines = ws.ws_row; } - m_suggestion_display = make<XtermSuggestionDisplay>(m_num_lines, m_num_columns, m_cached_prompt_metrics); -} - -Editor::~Editor() -{ - if (m_initialized) - restore(); } void Editor::add_to_history(const String& line) @@ -238,6 +243,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(); auto* term = getenv("TERM"); if (StringView { term }.starts_with("xterm")) @@ -974,26 +981,14 @@ void Editor::refresh_display() // Someone changed the window size, figure it out // and react to it, we might need to redraw. if (m_was_resized) { - auto previous_num_columns = m_num_columns; - - struct winsize ws; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) { - m_num_columns = 80; - m_num_lines = 25; - } else { - m_num_columns = ws.ws_col; - m_num_lines = ws.ws_row; - } - m_suggestion_display->set_vt_size(m_num_lines, m_num_columns); - - if (previous_num_columns != m_num_columns) { + if (m_previous_num_columns != m_num_columns) { // We need to cleanup and redo everything. m_cached_prompt_valid = false; m_refresh_needed = true; - swap(previous_num_columns, m_num_columns); + swap(m_previous_num_columns, m_num_columns); recalculate_origin(); cleanup(); - swap(previous_num_columns, m_num_columns); + swap(m_previous_num_columns, m_num_columns); has_cleaned_up = true; } m_was_resized = false; diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index 2f9fb4693e..4fb2d14a70 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -124,7 +124,9 @@ public: void resized() { m_was_resized = true; - refresh_display(); + m_previous_num_columns = m_num_columns; + get_terminal_size(); + m_suggestion_display->set_vt_size(m_num_lines, m_num_columns); } size_t cursor() const { return m_cursor; } @@ -308,6 +310,8 @@ private: }; CodepointRange byte_offset_range_to_codepoint_offset_range(size_t byte_start, size_t byte_end, size_t codepoint_scan_offset, bool reverse = false) const; + void get_terminal_size(); + bool m_finish { false }; RefPtr<Editor> m_search_editor; @@ -331,6 +335,7 @@ private: size_t m_times_tab_pressed { 0 }; size_t m_num_columns { 0 }; size_t m_num_lines { 1 }; + size_t m_previous_num_columns { 0 }; size_t m_extra_forward_lines { 0 }; StringMetrics m_cached_prompt_metrics; StringMetrics m_old_prompt_metrics; |