From f3b1c84a29e272cc589c300bca5020ccd4685a02 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 26 Oct 2026 20:02:16 +0100 Subject: terminal: fix signal handling state restore --- ttwhy/terminal/scoped_attributes.cppm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ttwhy/terminal/scoped_attributes.cppm') diff --git a/ttwhy/terminal/scoped_attributes.cppm b/ttwhy/terminal/scoped_attributes.cppm index 56fbe58..2d82826 100644 --- a/ttwhy/terminal/scoped_attributes.cppm +++ b/ttwhy/terminal/scoped_attributes.cppm @@ -150,9 +150,38 @@ namespace ttwhy::terminal return std::move(*this); } + //! Capture the currently active terminal mode and mark the attributes as suspended. + //! + //! Must be called before the terminal mode is changed while the process is being stopped. + auto suspend() & -> scoped_attributes & + { + if (m_file_descriptor > 0) + { + m_suspended = true; + m_suspended_canonical = canonical_mode(); + m_suspended_echo = echo(); + } + return *this; + } + + //! Restore the terminal mode captured before suspension. + auto resume() & -> scoped_attributes & + { + if (m_suspended) + { + canonical_mode(m_suspended_canonical); + echo(m_suspended_echo); + m_suspended = false; + } + return *this; + } + private: int m_file_descriptor; termios m_attributes; + bool m_suspended{false}; + bool m_suspended_canonical{false}; + bool m_suspended_echo{false}; }; } // namespace ttwhy::terminal -- cgit v1.2.3