From 46fd9317e5fa2ddbe813ab37cca57d3203cdd1f2 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 28 Jan 2022 01:51:23 -0500 Subject: [PATCH] notcurses-input: use getopt, no mice with -m #2579 --- src/input/input.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index b8e122903..821f7a8f7 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -417,19 +418,29 @@ int main(int argc, char** argv){ nopts.margin_r = 2; nopts.margin_b = 2; nopts.loglevel = NCLOGLEVEL_ERROR; - // FIXME handle -m to inhibit mice events - if(argc > 2){ - usage(argv[0], stderr); - }else if(argc == 2){ - if(strcmp(argv[1], "-v") == 0){ - nopts.loglevel = NCLOGLEVEL_TRACE; - }else{ - usage(argv[0], stderr); + bool nomice = false; + int opt; + while((opt = getopt(argc, argv, "vm")) != -1){ + switch(opt){ + case 'm': + nomice = true; + break; + case 'v': + nopts.loglevel = NCLOGLEVEL_TRACE; + break; + default: + usage(argv[0], stderr); + break; } } + if(argv[optind]){ // non-option argument was provided + usage(argv[0], stderr); + } nopts.flags = NCOPTION_INHIBIT_SETLOCALE; NotCurses nc(nopts); - nc.mouse_enable(NCMICE_ALL_EVENTS); + if(!nomice){ + nc.mouse_enable(NCMICE_ALL_EVENTS); + } int ret = input_demo(&nc); if(!nc.stop() || ret){ return EXIT_FAILURE;