8#elif defined(__unix__) || defined(__unix) || defined(__gnu_linux__)
13 #error "Platform other than Windows and Unix-like not supported yet"
23#if defined(__unix__) || defined(__unix) || defined(__gnu_linux__)
41 struct termios m_oldAttr, m_curAttr;
55 CONSOLE_SCREEN_BUFFER_INFO info;
57 const HANDLE hConsole =GetStdHandle(STD_OUTPUT_HANDLE);
58 if (INVALID_HANDLE_VALUE != hConsole &&
59 GetConsoleScreenBufferInfo(hConsole, &info))
60 FillConsoleOutputCharacter(hConsole,
' ', info.dwSize.X-info.dwCursorPosition.X,
61 info.dwCursorPosition, &_);
66 const HANDLE hConsole =GetStdHandle(STD_OUTPUT_HANDLE);
67 if (INVALID_HANDLE_VALUE != hConsole)
68 SetConsoleCursorPosition(hConsole, pos);
73 CONSOLE_SCREEN_BUFFER_INFO info;
74 const HANDLE hConsole =GetStdHandle(STD_OUTPUT_HANDLE);
75 if (INVALID_HANDLE_VALUE != hConsole &&
76 GetConsoleScreenBufferInfo(hConsole, &info))
77 return info.dwCursorPosition;
79 static const COORD def ={0, 0};
87#if defined(__unix__) || defined(__unix) || defined(__gnu_linux__)
88FC_GetChar::FC_GetChar(): m_dirty(false)
90 tcgetattr(0, &m_oldAttr);
91 m_curAttr = m_oldAttr;
94FC_GetChar::~FC_GetChar()
96 if (m_curAttr.c_lflag != m_oldAttr.c_lflag)
97 tcsetattr(0, TCSANOW, &m_oldAttr);
100int FC_GetChar::operator()()
106void FC_GetChar::bufferOff()
108 m_curAttr.c_lflag &= unsigned(~ICANON);
112void FC_GetChar::echoOff()
114 m_curAttr.c_lflag &= unsigned(~ECHO);
119void FC_GetChar::bufferOn()
121 m_curAttr.c_lflag |= ICANON;
125void FC_GetChar::echoOn()
127 m_curAttr.c_lflag |= ECHO;
131bool FC_GetChar::kbhit()
134 const int oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
135 fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
136 const int ch = getchar();
137 fcntl(STDIN_FILENO, F_SETFL, oldf);
148void FC_GetChar::updateAttr()
152 tcsetattr(0, TCSANOW, &m_curAttr);
165void getKeyPunch(std::string_view msg,
int &key,
const char *keyFilter)
171#elif defined(__unix__) || defined(__unix) || defined(__gnu_linux__)
177 while (keyFilter && !strchr(keyFilter, c));
179 std::cerr <<char(c) <<
'\n';
187#elif defined(__unix__) || defined(__unix) || defined(__gnu_linux__)
198 if (!_access(file, 0))
199#elif defined(__unix__) || defined(__unix) || defined(__gnu_linux__)
200 if (!access(file, F_OK))
204 getKeyPunch(std::string(file).
append(
" already exists. Overwrite it ?(y/n)"), c,
"ynYN");
205 if (c ==
'n' || c ==
'N')
THE common namespace of bux library.
bool testWritability(const char *file)
void getKeyPunch(std::string_view msg, int &key, const char *keyFilter)
void append(const T &src, std::string &dst)