Add feature for times of playing a vtv file. - vtv-tools - virtual terminal video tools HTML git clone git://bitreich.org/vtv-tools git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/vtv-tools DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 9e02589616cb962968de2b2dbca952b449cc1b1d DIR parent 270447f8aa7f318640c5dc7df3c759912d3bc37b HTML Author: Christoph Lohmann <20h@r-36.net> Date: Sat, 10 Aug 2024 09:30:40 +0200 Add feature for times of playing a vtv file. Diffstat: M man/vtv-player.1 | 4 +++- M src/vtv-player.c | 14 +++++++++++--- M src/vtv-viewer.c | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) --- DIR diff --git a/man/vtv-player.1 b/man/vtv-player.1 @@ -22,8 +22,10 @@ Plays a VTV file in the terminal. Loops until manually terminated. .Bl -tag -width Ds .It Fl r Ar fps Show this many frames per second. Defaults to 20. -.It Fl h Ar lines +.It Fl h Ar frameheight The number of lines in a frame. Defaults to 25. +.It Fl t Ar times +The number of times the vtv will be played. Default indefinite. .El . .Sh FORMAT DIR diff --git a/src/vtv-player.c b/src/vtv-player.c @@ -29,17 +29,21 @@ void sigint(int unused) { int main(int argc, char* argv[]) { int fps = 20; int frame_lines = 25; + int times = -1; const char *vtv_file; struct vtv* vtv; while (1) { - switch (getopt(argc, argv, "r:h:")) { + switch (getopt(argc, argv, "r:h:t:")) { case 'r': fps = atoi(optarg); break; case 'h': frame_lines = atoi(optarg); break; + case 't': + times = atoi(optarg); + break; case -1: if (optind == argc-1) { vtv_file = argv[optind]; @@ -47,7 +51,7 @@ int main(int argc, char* argv[]) { } // fallthrough default: - fprintf(stderr, "Usage: %s [-r INT] [-h INT] FILE\n", argv[0]); + fprintf(stderr, "Usage: %s [-r fps] [-h frameheight] [-t times] FILE\n", argv[0]); exit(1); } } @@ -67,13 +71,17 @@ int main(int argc, char* argv[]) { int frame = 0; signal(SIGINT, sigint); - while (1) { + for (int i = times; i != 0; i--) { useconds_t nap = 1000000.0 / fps; frame = (frame+1) % num_frames; home(); vtv_show_frame(vtv, stdout, frame, frame_lines, "\033[0m MISSING LINE"); usleep(nap); + if (i < 0) + i = -1; } def(); + reset(); } + DIR diff --git a/src/vtv-viewer.c b/src/vtv-viewer.c @@ -116,3 +116,4 @@ int main(int argc, char** argv) { vtv_free(vtv); return ret; } +