1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "command.h"
#include "gui.h"
namespace {
std::string trim(const std::string &s) {
size_t left = 0;
while (left < s.size() && isspace(s[left])) left++;
size_t right = s.size() - 1;
while (right >= left && isspace(s[right])) right--;
return s.substr(left, right - left + 1);
}
}
namespace gui {
void showNotification(const std::string &message) {
runCommand({"zenity", "--notification", "--text", message});
}
std::optional<std::string> promptText(const std::string &message) {
auto result = readCommand({"zenity", "--entry", "--text", message});
if (result.first == 0) return result.second;
else return std::nullopt;
}
std::optional<std::string> chooseList(const std::string &message, const std::string &header, const std::vector<std::string> &options) {
std::vector<std::string> args{
"zenity", "--list", "--text", message, "--column", header
};
args.insert(args.end(), options.begin(), options.end());
auto result = readCommand(args);
if (result.first == 0) return trim(result.second);
else return std::nullopt;
}
}
|