#include "terminal.hpp" TerminalState::TerminalState(termios term_attrs) noexcept : _term_attrs(term_attrs) {} void TerminalState::set_input_mode_flag(TerminalInputModeFlag flag, bool is_on) noexcept { auto flag_num = static_cast(flag); _term_attrs.c_iflag &= is_on ? flag_num : ~flag_num; } void TerminalState::set_output_mode_flag(TerminalOutputModeFlag flag, bool is_on) noexcept { auto flag_num = static_cast(flag); _term_attrs.c_oflag &= is_on ? flag_num : ~flag_num; } void TerminalState::set_control_mode_flag( TerminalControlModeFlag flag, bool is_on) noexcept { auto flag_num = static_cast(flag); _term_attrs.c_cflag &= is_on ? flag_num : ~flag_num; } void TerminalState::set_local_mode_flag(TerminalLocalModeFlag flag, bool is_on) noexcept { auto flag_num = static_cast(flag); _term_attrs.c_lflag &= is_on ? flag_num : ~flag_num; } auto TerminalState::get_attributes() noexcept -> termios { return _term_attrs; } auto get_terminal_state(int term_fd) noexcept -> TerminalState { termios term_attrs{}; tcgetattr(term_fd, &term_attrs); return TerminalState(term_attrs); } void set_terminal_state(int term_fd, TerminalState state) noexcept { auto state_attrs = state.get_attributes(); tcsetattr(term_fd, TCSAFLUSH, &state_attrs); }