Added -r option for random module
This commit is contained in:
parent
66b8909e67
commit
c484e8e6e3
15
main.cpp
15
main.cpp
@ -39,6 +39,7 @@ void print_help() {
|
||||
std::cout << "usage: screensaver [-h|-l|--version]\n";
|
||||
std::cout << " -h, --help show this help text and exit\n";
|
||||
std::cout << " -l, --list show available screensaver modules and exit\n";
|
||||
std::cout << " -r, --random choose random module from available ones\n";
|
||||
std::cout << " --version show version number and exit\n";
|
||||
}
|
||||
|
||||
@ -92,15 +93,16 @@ int main(int argc, const char * argv[]) {
|
||||
sc::plugin<ScreensaverPlugin>::scan_plugins("/usr/local/share/screensaver/plugins", "saver");
|
||||
#endif
|
||||
std::unique_ptr<ScreensaverPlugin> saver;
|
||||
|
||||
bool random_saver {false};
|
||||
int opt_char, opt_val;
|
||||
struct option long_options[] = {
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{"list", no_argument, nullptr, 'l'},
|
||||
{"random", no_argument, nullptr, 'r'},
|
||||
{"version", no_argument, &opt_val, 1},
|
||||
{nullptr, 0, nullptr, 0}
|
||||
};
|
||||
while ((opt_char = getopt_long(argc, const_cast<char* const *>(argv), "hl", long_options, nullptr)) != -1) {
|
||||
while ((opt_char = getopt_long(argc, const_cast<char* const *>(argv), "hlr", long_options, nullptr)) != -1) {
|
||||
std::string arg {optarg ? optarg : ""};
|
||||
switch (opt_char) {
|
||||
case 0: {
|
||||
@ -118,13 +120,20 @@ int main(int argc, const char * argv[]) {
|
||||
case 'l':
|
||||
list_plugins();
|
||||
return EXIT_SUCCESS;
|
||||
case 'r':
|
||||
random_saver = true;
|
||||
break;
|
||||
case '?':
|
||||
throw std::runtime_error("unrecognized option");
|
||||
}
|
||||
}
|
||||
if (optind == argc) {
|
||||
// here when no file args
|
||||
saver = sc::plugin<ScreensaverPlugin>::get("Default")();
|
||||
if (random_saver) {
|
||||
saver = sc::plugin<ScreensaverPlugin>::random_choice()();
|
||||
} else {
|
||||
saver = sc::plugin<ScreensaverPlugin>::get("Default")();
|
||||
}
|
||||
}
|
||||
for (int i = optind; i < argc; ++i) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user