diff --git a/main.cpp b/main.cpp index 8b2f986..f7e1f0f 100644 --- a/main.cpp +++ b/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::scan_plugins("/usr/local/share/screensaver/plugins", "saver"); #endif std::unique_ptr 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(argv), "hl", long_options, nullptr)) != -1) { + while ((opt_char = getopt_long(argc, const_cast(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::get("Default")(); + if (random_saver) { + saver = sc::plugin::random_choice()(); + } else { + saver = sc::plugin::get("Default")(); + } } for (int i = optind; i < argc; ++i) { try {