From 11558c9fcf018903bba61ea1c6424d30ce3d5e1b Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 14 Jun 2024 00:28:09 +0000 Subject: [PATCH] allow disabling thumbnail mode via --thumbnail=no the short opt -t does not accept optional argument since it'd break short option chaining. e.g `nsxiv -tp` currently works as `nsxiv -t -p` but if `-t` accepted optional argument then it'd stop working since "p" will be interpreted as argument to `-t` instead of being a flag. ref: https://codeberg.org/nsxiv/nsxiv/issues/404 --- etc/nsxiv.1 | 4 ++-- options.c | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/etc/nsxiv.1 b/etc/nsxiv.1 index 2e01302..999f91b 100644 --- a/etc/nsxiv.1 +++ b/etc/nsxiv.1 @@ -99,8 +99,8 @@ may be a floating-point number. Set scale mode according to MODE character. Supported modes are: [d]own, [f]it, [F]ill, [w]idth, [h]eight. .TP -.B "\-t, \-\-thumbnail" -Start in thumbnail mode. +.BR "\-t, \-\-thumbnail" [=no] +Start in thumbnail mode. The long option accepts an optional "no" to disable it. .TP .B "\-v, \-\-version" Print version information to standard output and exit. diff --git a/options.c b/options.c index 933485e..b9a244c 100644 --- a/options.c +++ b/options.c @@ -76,6 +76,7 @@ void parse_options(int argc, char **argv) OPT_START = UCHAR_MAX, OPT_AA, OPT_AL, + OPT_THUMB, OPT_BG, OPT_CA, OPT_CD @@ -99,7 +100,9 @@ void parse_options(int argc, char **argv) { "recursive", 'r', OPTPARSE_NONE }, { "ss-delay", 'S', OPTPARSE_REQUIRED }, { "scale-mode", 's', OPTPARSE_REQUIRED }, - { "thumbnail", 't', OPTPARSE_NONE }, + /* short opt `-t` doesn't accept optional arg for backwards compatibility reasons */ + { NULL, 't', OPTPARSE_NONE }, + { "thumbnail", OPT_THUMB, OPTPARSE_OPTIONAL }, { "version", 'v', OPTPARSE_NONE }, { "zoom-100", 'Z', OPTPARSE_NONE }, { "zoom", 'z', OPTPARSE_REQUIRED }, @@ -268,6 +271,11 @@ void parse_options(int argc, char **argv) error(EXIT_FAILURE, 0, "Invalid argument for option --alpha-layer: %s", op.optarg); _options.alpha_layer = op.optarg == NULL; break; + case OPT_THUMB: + if (op.optarg != NULL && !STREQ(op.optarg, "no")) + error(EXIT_FAILURE, 0, "Invalid argument for option --thumbnail: %s", op.optarg); + _options.thumb_mode = op.optarg == NULL; + break; case OPT_BG: if (op.optarg != NULL && !STREQ(op.optarg, "no")) error(EXIT_FAILURE, 0, "Invalid argument for option --bg-cache: %s", op.optarg);