|
|
vtv-player.c - vtv-tools - virtual terminal video tools |
|
|
 |
git clone git://bitreich.org/vtv-tools git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/vtv-tools (git://bitreich.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
Tags |
|
|
 |
README |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
|
vtv-player.c (1695B) |
|
|
|
--- |
|
|
|
1 // Copyright 2023 Troels Henriksen <athas@sigkill.dk> |
|
|
|
2 // |
|
|
|
3 // See LICENSE file for licensing information. |
|
|
|
4 |
|
|
|
5 #include <stdio.h> |
|
|
|
6 #include <stdlib.h> |
|
|
|
7 #include <unistd.h> |
|
|
|
8 #include <errno.h> |
|
|
|
9 #include <string.h> |
|
|
|
10 #include <signal.h> |
|
|
|
11 |
|
|
|
12 #include "vtv.h" |
|
|
|
13 |
|
|
|
14 void hide_cursor() { printf("\033[?25l"); } |
|
|
|
15 void show_cursor() { printf("\033[?25h"); } |
|
|
|
16 void move(int x, int y) { printf("\033[%d;%dH", y, x); } |
|
|
|
17 void home() { printf("\033[;H"); } |
|
|
|
18 void clear_screen() { printf("\033[2J"); } |
|
|
|
19 void clear_line() { printf("\033[2K"); } |
|
|
|
20 void def() { printf("\033[0m"); } |
|
|
|
21 void reset() { printf("\033c"); } |
|
|
|
22 |
|
|
|
23 void sigint(int unused) { |
|
|
|
24 (void)unused; |
|
|
|
25 reset(); |
|
|
|
26 exit(0); |
|
|
|
27 } |
|
|
|
28 |
|
|
|
29 int main(int argc, char* argv[]) { |
|
|
|
30 int fps = 20; |
|
|
|
31 int frame_lines = 25; |
|
|
|
32 const char *vtv_file; |
|
|
|
33 struct vtv* vtv; |
|
|
|
34 |
|
|
|
35 while (1) { |
|
|
|
36 switch (getopt(argc, argv, "r:h:")) { |
|
|
|
37 case 'r': |
|
|
|
38 fps = atoi(optarg); |
|
|
|
39 break; |
|
|
|
40 case 'h': |
|
|
|
41 frame_lines = atoi(optarg); |
|
|
|
42 break; |
|
|
|
43 case -1: |
|
|
|
44 if (optind == argc-1) { |
|
|
|
45 vtv_file = argv[optind]; |
|
|
|
46 goto done; |
|
|
|
47 } |
|
|
|
48 // fallthrough |
|
|
|
49 default: |
|
|
|
50 fprintf(stderr, "Usage: %s [-r INT] FILE\n", argv[0]); |
|
|
|
51 exit(1); |
|
|
|
52 } |
|
|
|
53 } |
|
|
|
54 done: |
|
|
|
55 vtv = vtv_read_from_file(vtv_file); |
|
|
|
56 if (vtv == NULL) { |
|
|
|
57 fprintf(stderr, "%s: cannot read %s: %s\n", |
|
|
|
58 argv[0], vtv_file, strerror(errno)); |
|
|
|
59 exit(1); |
|
|
|
60 } |
|
|
|
61 |
|
|
|
62 int num_frames = vtv->num_lines / frame_lines; |
|
|
|
63 |
|
|
|
64 hide_cursor(); |
|
|
|
65 clear_screen(); |
|
|
|
66 |
|
|
|
67 int frame = 0; |
|
|
|
68 signal(SIGINT, sigint); |
|
|
|
69 |
|
|
|
70 while (1) { |
|
|
|
71 useconds_t nap = 1000000.0 / fps; |
|
|
|
72 frame = (frame+1) % num_frames; |
|
|
|
73 home(); |
|
|
|
74 vtv_show_frame(vtv, stdout, frame, frame_lines, |
|
|
|
75 "\033[0m MISSING LINE"); |
|
|
|
76 usleep(nap); |
|
|
|
77 } |
|
|
|
78 def(); |
|
|
|
79 } |
|