6 #ifndef PLATFORM_WINDOWS 25 cout << (defaultResponse == Response::Yes ?
'Y' :
'y');
26 cout <<
'/' << (defaultResponse == Response::No ?
'N' :
'n');
31 if (line ==
"y" || line ==
"Y" || (defaultResponse == Response::Yes && line.empty())) {
33 }
else if (line ==
"n" || line ==
"N" || (defaultResponse == Response::No && line.empty())) {
36 cout <<
"Please enter [y] or [n]: ";
49 #ifndef PLATFORM_WINDOWS 50 ioctl(STDOUT_FILENO, TIOCGWINSZ, reinterpret_cast<winsize *>(&size));
52 CONSOLE_SCREEN_BUFFER_INFO consoleBufferInfo;
53 if (
const HANDLE stdHandle = GetStdHandle(STD_OUTPUT_HANDLE)) {
54 GetConsoleScreenBufferInfo(stdHandle, &consoleBufferInfo);
55 if (consoleBufferInfo.dwSize.X > 0) {
56 size.
columns = static_cast<unsigned short>(consoleBufferInfo.dwSize.X);
58 if (consoleBufferInfo.dwSize.Y > 0) {
59 size.
rows = static_cast<unsigned short>(consoleBufferInfo.dwSize.Y);
66 #ifdef PLATFORM_WINDOWS 76 if (
auto *consoleWindow = GetConsoleWindow()) {
77 PostMessage(consoleWindow, WM_KEYUP, VK_RETURN, 0);
91 if (!AttachConsole(ATTACH_PARENT_PROCESS) && !AllocConsole()) {
95 auto stdHandle = reinterpret_cast<intptr_t>(GetStdHandle(STD_OUTPUT_HANDLE));
96 auto conHandle = _open_osfhandle(stdHandle, _O_TEXT);
97 auto fp = _fdopen(conHandle,
"w");
99 setvbuf(stdout,
nullptr, _IONBF, 0);
101 stdHandle = reinterpret_cast<intptr_t>(GetStdHandle(STD_INPUT_HANDLE));
102 conHandle = _open_osfhandle(stdHandle, _O_TEXT);
103 fp = _fdopen(conHandle,
"r");
105 setvbuf(stdin,
nullptr, _IONBF, 0);
107 stdHandle = reinterpret_cast<intptr_t>(GetStdHandle(STD_ERROR_HANDLE));
108 conHandle = _open_osfhandle(stdHandle, _O_TEXT);
109 fp = _fdopen(conHandle,
"w");
111 setvbuf(stderr,
nullptr, _IONBF, 0);
112 #ifdef CPP_UTILITIES_FORCE_UTF8_CODEPAGE 115 SetConsoleCP(CP_UTF8);
116 SetConsoleOutputCP(CP_UTF8);
119 ios::sync_with_stdio(
true);
128 pair<vector<unique_ptr<char[]>>, vector<char *>> convertArgsToUtf8()
130 pair<vector<unique_ptr<char[]>>, vector<char *>> res;
133 LPWSTR *argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
134 if (!argv_w || argc <= 0) {
138 res.first.reserve(static_cast<size_t>(argc));
139 res.second.reserve(static_cast<size_t>(argc));
140 for (LPWSTR *
i = argv_w, *end = argv_w + argc;
i != end; ++
i) {
141 int requiredSize = WideCharToMultiByte(CP_UTF8, 0, *
i, -1,
nullptr, 0, 0, 0);
142 if (requiredSize <= 0) {
146 auto argv = make_unique<char[]>(static_cast<size_t>(requiredSize));
147 requiredSize = WideCharToMultiByte(CP_UTF8, 0, *
i, -1, argv.get(), requiredSize, 0, 0);
148 if (requiredSize <= 0) {
152 res.second.emplace_back(argv.get());
153 res.first.emplace_back(move(argv));
unsigned short rows
number of rows
Contains currently only ArgumentParser and related classes.
bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultResponse=Response::None)
Prompts for confirmation displaying the specified message.
Response
The Response enum is used to specify the default response for the confirmPrompt() method.
The TerminalSize struct describes a terminal size.
TerminalSize CPP_UTILITIES_EXPORT determineTerminalSize()
Returns the current size of the terminal.
unsigned short columns
number of columns