Set mode raw/cooked.
First call is to save the good state set-up by cpp-terminal.
168{
169 static bool activated{false};
170#if defined(_WIN32)
171 static DWORD flags{0};
172 if(!activated)
173 {
175 if(!GetConsoleMode(
Private::in.handle(), &flags)) {
throw Term::Private::WindowsException(GetLastError()); }
176 activated = true;
177 return;
178 }
179 DWORD send = flags;
181 {
182 send &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
184 }
186 {
187 send |= (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT);
189 }
193 if(!SetConsoleMode(
Private::in.handle(), send)) {
throw Term::Private::WindowsException(GetLastError()); }
194#else
196 {
197 static ::termios raw = {};
198 if(!activated)
199 {
200 Term::Private::Errno().check_if(tcgetattr(
Private::out.fd(), &raw) == -1).throw_exception(
"tcgetattr(Private::out.fd(), &raw)");
201 raw.c_cflag &= ~static_cast<std::size_t>(CSIZE | PARENB);
202 raw.c_cflag |= CS8;
203 raw.c_cc[VMIN] = 1;
204 raw.c_cc[VTIME] = 0;
205 activated = true;
206 return;
207 }
208 ::termios send = raw;
210 {
211 send.c_iflag &= ~static_cast<std::size_t>(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | INPCK);
212
213
214
215
216 send.c_lflag &= ~static_cast<std::size_t>(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
219 }
221 {
222 send = raw;
225 }
228 Term::Private::Errno().check_if(tcsetattr(
Private::out.fd(), TCSAFLUSH, &send) == -1).throw_exception(
"tcsetattr(Private::out.fd(), TCSAFLUSH, &send)");
229 }
230#endif
231}
static std::size_t setFocusEvents()
static std::size_t setMouseEvents()
@ Cooked
Set terminal in cooked mode.
@ Raw
Set terminal in raw mode.
@ NoSignalKeys
Disable the signal keys (Ctrl+C, etc...) will not be processed by the OS and will appears has standar...
@ SignalKeys
Enable the signal keys (Ctrl+C, etc...), if activated these keys will have their default OS behaviour...