multiprogress.c: Remove pointless return value from `setup_render_state'.
[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 char pc; /* pad character (termcap) */
17 } cap;
18 unsigned defwd, defht; /* default width and height */
19 };
20 #define PROGRESS_TTYINFO_INIT \
21 { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 80, 25 }
22
23 struct progress_state {
24 struct progress_ttyinfo tty; /* terminal state */
25 struct progress_item *items, *end_item; /* list of progress items */
26 unsigned nitems; /* number of items */
27 unsigned last_lines; /* number written last time */
28 struct timeval tv_update; /* last update time */
29 };
30 #define PROGRESS_STATE_INIT { PROGRESS_TTYINFO_INIT, 0, 0, 0, 0, { 0, 0 } }
31
32 struct progress_render_state {
33 const struct progress_ttyinfo *tty; /* terminal state */
34 unsigned width, height; /* terminal size, in characters */
35 char *linebuf; size_t linesz; /* output buffer */
36 char *tempbuf; size_t tempsz; /* scratch buffer */
37 size_t leftsz, rightsz; /* left and right cursors */
38 unsigned leftwd, rightwd; /* left and right widths */
39 char *old_bc, *old_up, old_pc; /* saved `termcap' globals */
40 };
41
42 struct progress_item {
43 struct progress_state *parent; /* controlling progress state */
44 struct progress_item *next, *prev; /* forward and backward links */
45 void (*render)(struct progress_item */*item*/, /* render function */
46 struct progress_render_state */*rs*/);
47 };
48 #define PROGRESS_ITEM_INIT { 0, 0, 0, 0 }
49
50 extern int progress_init(struct progress_state */*progress*/);
51 extern void progress_free(struct progress_state */*progress*/);
52
53 extern int progress_additem(struct progress_state */*progress*/,
54 struct progress_item */*item*/);
55
56 extern int progress_removeitem(struct progress_state */*progress*/,
57 struct progress_item */*item*/);
58
59 extern int progress_clear(struct progress_state */*progress*/);
60
61 extern int progress_update(struct progress_state */*progress*/);
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