multiprogress.h: Add the right number of zeros to `PROGRESS_TTYINFO_INIT'.
[dvdrip] / multiprogress.h
1 #ifndef MULTIPROGRESS_H
2 #define MULTIPROGRESS_H
3
4 #include <stdio.h>
5 #include <sys/time.h>
6
7 struct progress_ttyinfo {
8 FILE *fp; /* terminal stream */
9 char *termbuf, *capbuf; /* buffers for termcap */
10 struct { /* terminal capabilities */
11 unsigned f; /* various flags */
12 #define TCF_BCE 1u /* erases to background colour */
13 const char *cr, *nw, *up, *ce, *cd; /* cursor motion */
14 const char *mr, *md, *me; /* reverse video, bold */
15 const char *af, *ab, *op; /* colour */
16 } cap;
17 unsigned defwd, defht; /* default width and height */
18 };
19 #define PROGRESS_TTYINFO_INIT \
20 { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 80, 25 }
21
22 struct progress_state {
23 struct progress_ttyinfo tty; /* terminal state */
24 struct progress_item *items, *end_item; /* list of progress items */
25 unsigned nitems; /* number of items */
26 unsigned last_lines; /* number written last time */
27 struct timeval tv_update; /* last update time */
28 };
29 #define PROGRESS_STATE_INIT { PROGRESS_TTYINFO_INIT, 0, 0, 0, 0, { 0, 0 } }
30
31 struct progress_render_state {
32 const struct progress_ttyinfo *tty; /* terminal state */
33 unsigned width, height; /* terminal size, in characters */
34 char *linebuf; size_t linesz; /* output buffer */
35 char *tempbuf; size_t tempsz; /* scratch buffer */
36 size_t leftsz, rightsz; /* left and right cursors */
37 unsigned leftwd, rightwd; /* left and right widths */
38 char *old_bc, *old_up; /* old fixup strings */
39 };
40
41 struct progress_item {
42 struct progress_state *parent; /* controlling progress state */
43 struct progress_item *next, *prev; /* forward and backward links */
44 void (*render)(struct progress_item */*item*/, /* render function */
45 struct progress_render_state */*rs*/);
46 };
47 #define PROGRESS_ITEM_INIT { 0, 0, 0, 0 }
48
49 extern int progress_init(struct progress_state */*progress*/);
50 extern void progress_free(struct progress_state */*progress*/);
51
52 extern int progress_clear(struct progress_state */*progress*/);
53
54 extern int progress_update(struct progress_state */*progress*/);
55
56 extern int progress_additem(struct progress_state */*progress*/,
57 struct progress_item */*item*/);
58
59 extern int progress_removeitem(struct progress_state */*progress*/,
60 struct progress_item */*item*/);
61
62
63 extern int progress_vputleft(struct progress_render_state */*render*/,
64 const char */*fmt*/, va_list /*ap*/);
65
66 extern int progress_vputright(struct progress_render_state */*render*/,
67 const char */*fmt*/, va_list /*ap*/);
68
69 __attribute__((format(printf, 2, 3)))
70 extern int progress_putleft(struct progress_render_state */*render*/,
71 const char */*fmt*/, ...);
72
73 __attribute__((format(printf, 2, 3)))
74 extern int progress_putright(struct progress_render_state */*render*/,
75 const char */*fmt*/, ...);
76
77 extern int progress_showbar(struct progress_render_state */*render*/,
78 double /*frac*/);
79
80 extern int progress_shownotice(struct progress_render_state */*render*/,
81 int /*bg*/, int /*fg*/);
82
83 #endif