7 #ifndef PLATFORM_WINDOWS
26 cout << (defaultResponse == Response::Yes ?
'Y' :
'y');
27 cout <<
'/' << (defaultResponse == Response::No ?
'N' :
'n');
32 if (line ==
"y" || line ==
"Y" || (defaultResponse == Response::Yes && line.empty())) {
34 }
else if (line ==
"n" || line ==
"N" || (defaultResponse == Response::No && line.empty())) {
37 cout <<
"Please enter [y] or [n]: ";
50 #ifndef PLATFORM_WINDOWS
51 ioctl(STDOUT_FILENO, TIOCGWINSZ,
reinterpret_cast<winsize *
>(&size));
53 CONSOLE_SCREEN_BUFFER_INFO consoleBufferInfo;
54 if (
const HANDLE stdHandle = GetStdHandle(STD_OUTPUT_HANDLE)) {
55 GetConsoleScreenBufferInfo(stdHandle, &consoleBufferInfo);
56 if (consoleBufferInfo.dwSize.X > 0) {
57 size.
columns =
static_cast<unsigned short>(consoleBufferInfo.dwSize.X);
59 if (consoleBufferInfo.dwSize.Y > 0) {
60 size.
rows =
static_cast<unsigned short>(consoleBufferInfo.dwSize.Y);
67 #ifdef PLATFORM_WINDOWS
77 if (
auto *
const consoleWindow = GetConsoleWindow()) {
78 PostMessage(consoleWindow, WM_KEYUP, VK_RETURN, 0);
102 if ((!consoleEnabled.has_value() || consoleEnabled.value()) && (AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole())) {
104 auto stdHandle =
reinterpret_cast<intptr_t
>(GetStdHandle(STD_OUTPUT_HANDLE));
105 auto conHandle = _open_osfhandle(stdHandle, _O_TEXT);
106 auto fp = _fdopen(conHandle,
"w");
108 setvbuf(stdout,
nullptr, _IONBF, 0);
110 stdHandle =
reinterpret_cast<intptr_t
>(GetStdHandle(STD_INPUT_HANDLE));
111 conHandle = _open_osfhandle(stdHandle, _O_TEXT);
112 fp = _fdopen(conHandle,
"r");
114 setvbuf(stdin,
nullptr, _IONBF, 0);
116 stdHandle =
reinterpret_cast<intptr_t
>(GetStdHandle(STD_ERROR_HANDLE));
117 conHandle = _open_osfhandle(stdHandle, _O_TEXT);
118 fp = _fdopen(conHandle,
"w");
120 setvbuf(stderr,
nullptr, _IONBF, 0);
122 ios::sync_with_stdio(
true);
129 if (!utf8Enabled.has_value() || utf8Enabled.value()) {
130 SetConsoleCP(CP_UTF8);
131 SetConsoleOutputCP(CP_UTF8);
139 pair<vector<unique_ptr<char[]>>, vector<char *>> convertArgsToUtf8()
141 pair<vector<unique_ptr<char[]>>, vector<char *>> res;
144 LPWSTR *argv_w = CommandLineToArgvW(GetCommandLineW(), &argc);
145 if (!argv_w || argc <= 0) {
149 res.first.reserve(
static_cast<size_t>(argc));
150 res.second.reserve(
static_cast<size_t>(argc));
151 for (LPWSTR *
i = argv_w, *end = argv_w + argc;
i != end; ++
i) {
152 int requiredSize = WideCharToMultiByte(CP_UTF8, 0, *
i, -1,
nullptr, 0, 0, 0);
153 if (requiredSize <= 0) {
157 auto argv = make_unique<char[]>(
static_cast<size_t>(requiredSize));
158 requiredSize = WideCharToMultiByte(CP_UTF8, 0, *
i, -1, argv.get(), requiredSize, 0, 0);
159 if (requiredSize <= 0) {
163 res.second.emplace_back(argv.get());
164 res.first.emplace_back(move(argv));
Contains all utilities provides by the c++utilities library.
CPP_UTILITIES_EXPORT TerminalSize determineTerminalSize()
Returns the current size of the terminal.
Response
The Response enum is used to specify the default response for the confirmPrompt() method.
CPP_UTILITIES_EXPORT bool confirmPrompt(const char *message, Response defaultResponse=Response::None)
Prompts for confirmation displaying the specified message.
std::optional< bool > isEnvVariableSet(const char *variableName)
Returns whether the specified env variable is set to a non-zero and non-white-space-only value.
The TerminalSize struct describes a terminal size.
unsigned short columns
number of columns
unsigned short rows
number of rows