stc
Loading...
Searching...
No Matches
IO.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#ifdef _WIN32
5#define NOMINMAX
6#include <windows.h>
7#else
8#include <termios.h>
9#include <unistd.h>
10#endif
11
12namespace stc {
13
39private:
40 bool freed = false;
41 void set(bool enable) {
42#ifdef _WIN32
43 HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
44 DWORD mode;
45 GetConsoleMode(hStdin, &mode);
46
47 if (!enable) {
48 mode &= ~ENABLE_ECHO_INPUT;
49 } else {
50 mode |= ENABLE_ECHO_INPUT;
51 }
52
53 SetConsoleMode(hStdin, mode);
54#else
55 struct termios tty;
56 tcgetattr(STDIN_FILENO, &tty);
57
58 if (!enable) {
59 tty.c_lflag &= ~ECHO;
60 } else {
61 tty.c_lflag |= ECHO;
62 }
63
64 tcsetattr(STDIN_FILENO, TCSANOW, &tty);
65#endif
66
67 }
68public:
70 set(false);
71 }
73 release();
74 }
75
76 void release() {
77 if (freed) return;
78 freed = true;
79
80 set(true);
81 }
82};
83
84}
Definition IO.hpp:38
PasswordIO()
Definition IO.hpp:69
~PasswordIO()
Definition IO.hpp:72
void release()
Definition IO.hpp:76
Definition CaptureStream.hpp:6