Add -d option for debug messages

This commit is contained in:
Nikita Ivanov 2023-04-10 00:53:46 +02:00
parent 83af722da2
commit 930535cbea
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
4 changed files with 16 additions and 1 deletions

View File

@ -9,6 +9,7 @@ ctpv \- terminal previewer
.SH SYNOPSIS
.
.SY ctpv
.RI [ \-d ]
.I file
.RI [ w ]
.RI [ h ]
@ -282,6 +283,10 @@ command to server with ID
Kill server with ID
.IR id .
.
.TP
.B \-d
Enable debug messages.
.
.SH CONFIGURATION
.
.B ctpv

View File

@ -411,9 +411,10 @@ int main(int argc, char *argv[])
program = argc > 0 ? argv[0] : "ctpv";
ctpv.opts.shell = "/bin/sh";
ctpv.debug = 0;
int c;
while ((c = getopt(argc, argv, "hs:c:e:lmv")) != -1) {
while ((c = getopt(argc, argv, "hs:c:e:lmdv")) != -1) {
switch (c) {
case 'h':
ctpv.mode = MODE_HELP;
@ -436,6 +437,9 @@ int main(int argc, char *argv[])
case 'm':
ctpv.mode = MODE_MIME;
break;
case 'd':
ctpv.debug = 1;
break;
case 'v':
ctpv.mode = MODE_VERSION;
break;

View File

@ -20,6 +20,7 @@ struct CTPV {
int autochafa, chafasixel, showgpg;
char *shell;
} opts;
int debug;
};
extern struct CTPV ctpv;

View File

@ -201,10 +201,15 @@ run:
return ERR;
}
if (ctpv.debug)
fprintf(stderr, "Running preview: %s\n", p->name);
ERRCHK_RET_OK(run(p, &exitcode, &signal));
switch (exitcode) {
case FAILED_PREVIEW_EC:
if (ctpv.debug)
fprintf(stderr, "Preview %s failed\n", p->name);
i++;
goto run;
case ENOUGH_READ_EC: