[lldb] [Host] Refactor TerminalState

Refactor TerminalState to make the code simpler.  Move 'struct termios'
to a PImpl-style subclass.  Add an RAII interface to automatically store
and restore the state.

Differential revision: https://reviews.llvm.org/D110721
This commit is contained in:
Michał Górny
2021-09-29 17:51:51 +02:00
parent 512aa84850
commit 58b4501eea
5 changed files with 51 additions and 81 deletions

View File

@@ -355,7 +355,6 @@ private:
PyEval_InitThreads();
}
TerminalState m_stdin_tty_state;
PyGILState_STATE m_gil_state = PyGILState_UNLOCKED;
bool m_was_already_initialized = false;
};

View File

@@ -430,11 +430,9 @@ public:
int stdin_fd = GetInputFD();
if (stdin_fd >= 0) {
Terminal terminal(stdin_fd);
TerminalState terminal_state;
const bool is_a_tty = terminal.IsATerminal();
TerminalState terminal_state(terminal);
if (is_a_tty) {
terminal_state.Save(stdin_fd, false);
if (terminal.IsATerminal()) {
terminal.SetCanonical(false);
terminal.SetEcho(true);
}
@@ -464,9 +462,6 @@ public:
run_string.Printf("run_python_interpreter (%s)",
m_python->GetDictionaryName());
PyRun_SimpleString(run_string.GetData());
if (is_a_tty)
terminal_state.Restore();
}
}
SetIsDone(true);