From 60165bacf93a6625571c38cc8ab7ea182b5b1dec Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 23 Oct 2021 09:42:31 +1100 Subject: [PATCH] Use DECRQM/DECRPM to detect support for synchronized output Enable it if supported by default, let the user override it with the existing terminal_synchronized ui option. This should finalize work discussed on #4317 --- src/terminal_ui.cc | 14 ++++++++++++-- src/terminal_ui.hh | 10 +++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc index 3ba87b3a..0cc4a311 100644 --- a/src/terminal_ui.cc +++ b/src/terminal_ui.cc @@ -531,7 +531,7 @@ void TerminalUI::redraw(bool force) m_info.blit(m_screen); Writer writer{STDOUT_FILENO}; - m_screen.output(force, m_synchronized, writer); + m_screen.output(force, (bool)m_synchronized, writer); auto set_cursor_pos = [&](DisplayCoord c) { format_with(writer, "\033[{};{}H", (int)c.line + 1, (int)c.column + 1); @@ -808,6 +808,12 @@ Optional TerminalUI::get_next_key() switch (c) { case '$': + if (private_mode == '?' and next_char() == 'y') // DECRPM + { + if (params[0] == 2026) + m_synchronized.supported = (params[0] != 0); + return {Key::Invalid}; + } switch (params[0]) { case 23: case 24: @@ -1401,6 +1407,7 @@ void TerminalUI::setup_terminal() "\033[22t" // save the current window title "\033[?25l" // hide cursor "\033=" // set application keypad mode, so the keypad keys send unique codes + "\033[?2026$p" // query support for synchronize output ); } @@ -1463,7 +1470,10 @@ void TerminalUI::set_ui_options(const Options& options) m_status_on_top = find("terminal_status_on_top").map(to_bool).value_or(false); m_set_title = find("terminal_set_title").map(to_bool).value_or(true); - m_synchronized = find("terminal_synchronized").map(to_bool).value_or(false); + + auto synchronized = find("terminal_synchronized").map(to_bool); + m_synchronized.set = (bool)synchronized; + m_synchronized.requested = synchronized.value_or(false); m_shift_function_key = find("terminal_shift_function_key").map(str_to_int_ifp).value_or(default_shift_function_key); diff --git a/src/terminal_ui.hh b/src/terminal_ui.hh index 8b1a4cfe..b02cbb33 100644 --- a/src/terminal_ui.hh +++ b/src/terminal_ui.hh @@ -151,7 +151,15 @@ private: int m_shift_function_key = default_shift_function_key; bool m_set_title = true; - bool m_synchronized = false; + + struct Synchronized + { + bool supported : 1; + bool set : 1; + bool requested : 1; + + explicit operator bool() const { return set ? requested : supported; } + } m_synchronized{}; Codepoint m_padding_char = '~'; bool m_padding_fill = false;