diff options
Diffstat (limited to 'gui.cpp')
-rw-r--r-- | gui.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,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; + } +} |