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
This commit is contained in:
NRK 2024-06-14 00:28:09 +00:00
parent 3408bbcdda
commit 11558c9fcf
2 changed files with 11 additions and 3 deletions

View file

@ -99,8 +99,8 @@ may be a floating-point number.
Set scale mode according to MODE character. Supported modes are: [d]own, Set scale mode according to MODE character. Supported modes are: [d]own,
[f]it, [F]ill, [w]idth, [h]eight. [f]it, [F]ill, [w]idth, [h]eight.
.TP .TP
.B "\-t, \-\-thumbnail" .BR "\-t, \-\-thumbnail" [=no]
Start in thumbnail mode. Start in thumbnail mode. The long option accepts an optional "no" to disable it.
.TP .TP
.B "\-v, \-\-version" .B "\-v, \-\-version"
Print version information to standard output and exit. Print version information to standard output and exit.

View file

@ -76,6 +76,7 @@ void parse_options(int argc, char **argv)
OPT_START = UCHAR_MAX, OPT_START = UCHAR_MAX,
OPT_AA, OPT_AA,
OPT_AL, OPT_AL,
OPT_THUMB,
OPT_BG, OPT_BG,
OPT_CA, OPT_CA,
OPT_CD OPT_CD
@ -99,7 +100,9 @@ void parse_options(int argc, char **argv)
{ "recursive", 'r', OPTPARSE_NONE }, { "recursive", 'r', OPTPARSE_NONE },
{ "ss-delay", 'S', OPTPARSE_REQUIRED }, { "ss-delay", 'S', OPTPARSE_REQUIRED },
{ "scale-mode", '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 }, { "version", 'v', OPTPARSE_NONE },
{ "zoom-100", 'Z', OPTPARSE_NONE }, { "zoom-100", 'Z', OPTPARSE_NONE },
{ "zoom", 'z', OPTPARSE_REQUIRED }, { "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); error(EXIT_FAILURE, 0, "Invalid argument for option --alpha-layer: %s", op.optarg);
_options.alpha_layer = op.optarg == NULL; _options.alpha_layer = op.optarg == NULL;
break; 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: case OPT_BG:
if (op.optarg != NULL && !STREQ(op.optarg, "no")) if (op.optarg != NULL && !STREQ(op.optarg, "no"))
error(EXIT_FAILURE, 0, "Invalid argument for option --bg-cache: %s", op.optarg); error(EXIT_FAILURE, 0, "Invalid argument for option --bg-cache: %s", op.optarg);