59 std::string prompt = std::format(
"Phasor {} {} {} the {}. Is this okay?", subsystem,
AConsentVolition[volition], verb, noun);
61 bool tty = _isatty(_fileno(stdin));
63 bool tty = isatty(fileno(stdin));
68 if (MessageBoxA(NULL, prompt.c_str(),
"Phasor Programming Language", MB_YESNO) == IDYES)
return true;
71 CFStringRef cfTitle = CFStringCreateWithCString(NULL,
"Phasor Programming Language", kCFStringEncodingUTF8);
72 CFStringRef cfMessage = CFStringCreateWithCString(NULL, prompt.c_str(), kCFStringEncodingUTF8);
74 CFOptionFlags responseFlags;
75 CFUserNotificationDisplayAlert(
77 kCFUserNotificationNoteAlertLevel,
92 return responseFlags == kCFUserNotificationAlternateResponse;
94 bool has_display = std::getenv(
"DISPLAY") || std::getenv(
"WAYLAND_DISPLAY");
95 if (!has_display)
return false;
97 const std::array<std::string, 2> tools = {
"zenity",
"kdialog"};
99 for (
const auto& tool : tools) {
101 if (tool ==
"zenity")
102 cmd = std::format(
"zenity --question --text='{}' 2>/dev/null", prompt);
104 cmd = std::format(
"kdialog --yesno '{}' 2>/dev/null", prompt);
106 int ret = std::system(cmd.c_str());
107 if (ret == 127)
continue;
109 if (WIFEXITED(ret) && WEXITSTATUS(ret) == 0)
118 std::print(
"{} {} ", prompt, default_val ?
"[Y/n]" :
"[y/N]");
119 std::getline(std::cin, line);
120 if (line.empty())
return default_val;
121 else if (line[0] ==
'y' || line[0] ==
'Y') res =
true;
122 else if (line[0] ==
'n' || line[0] ==
'N') res =
false;
bool prompt_consent(const char(&subsystem)[N1], EConsentVolition volition, const char(&verb)[N2], const char(&noun)[N3], bool default_val=false)
Prompt the user for consent.