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

View File

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

View File

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

View File

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