set title based on prefix and suffix (#23)

Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com>
Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
This commit is contained in:
qsmodo
2021-09-12 15:26:07 -03:00
committed by Berke Kocaoğlu
parent 91d9b3128e
commit 156a53780c
7 changed files with 74 additions and 7 deletions

View File

@ -18,6 +18,7 @@
#include "sxiv.h"
#define _IMAGE_CONFIG
#define _TITLE_CONFIG
#include "config.h"
#include "version.h"
@ -31,8 +32,8 @@ const opt_t *options = (const opt_t*) &_options;
void print_usage(void)
{
printf("usage: sxiv [-abcfhiopqrtvZ] [-A FRAMERATE] [-e WID] [-G GAMMA] "
"[-g GEOMETRY] [-N NAME] [-n NUM] [-S DELAY] [-s MODE] [-z ZOOM] "
"FILES...\n");
"[-g GEOMETRY] [-N NAME] [-T TITLE] [-n NUM] [-S DELAY] [-s MODE] "
"[-z ZOOM] FILES...\n");
}
void print_version(void)
@ -66,13 +67,15 @@ void parse_options(int argc, char **argv)
_options.hide_bar = false;
_options.geometry = NULL;
_options.res_name = NULL;
_options.title_prefix = TITLE_PREFIX;
_options.title_suffixmode = TITLE_SUFFIXMODE;
_options.quiet = false;
_options.thumb_mode = false;
_options.clean_cache = false;
_options.private_mode = false;
while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:tvZz:")) != -1) {
while ((opt = getopt(argc, argv, "A:abce:fG:g:hin:N:opqrS:s:T:tvZz:")) != -1) {
switch (opt) {
case '?':
print_usage();
@ -149,6 +152,16 @@ void parse_options(int argc, char **argv)
error(EXIT_FAILURE, 0, "Invalid argument for option -s: %s", optarg);
_options.scalemode = s - scalemodes;
break;
case 'T':
if ((s = strrchr(optarg, ':')) != NULL) {
*s = '\0';
n = strtol(++s, &end, 0);
if (*end != '\0' || n < SUFFIX_EMPTY || n > SUFFIX_FULLPATH)
error(EXIT_FAILURE, 0, "Invalid argument for option -T suffixmode: %s", s);
_options.title_suffixmode = n;
}
_options.title_prefix = optarg;
break;
case 't':
_options.thumb_mode = true;
break;