1 #ifndef MULTIPROGRESS_H
2 #define MULTIPROGRESS_H
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 */
17 unsigned defwd, defht; /* default width and height */
19 #define PROGRESS_TTYINFO_INIT { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
21 struct progress_state {
22 struct progress_ttyinfo tty; /* terminal state */
23 struct progress_item *items, *end_item; /* list of progress items */
24 unsigned nitems; /* number of items */
25 unsigned last_lines; /* number written last time */
26 struct timeval tv_update; /* last update time */
28 #define PROGRESS_STATE_INIT { PROGRESS_TTYINFO_INIT, 0, 0, 0, 0, { 0, 0 } }
30 struct progress_render_state {
31 const struct progress_ttyinfo *tty; /* terminal state */
32 unsigned width, height; /* terminal size, in characters */
33 char *linebuf; size_t linesz; /* output buffer */
34 char *tempbuf; size_t tempsz; /* scratch buffer */
35 size_t leftsz, rightsz; /* left and right cursors */
36 unsigned leftwd, rightwd; /* left and right widths */
37 char *old_bc, *old_up; /* old fixup strings */
40 struct progress_item {
41 struct progress_state *parent; /* controlling progress state */
42 struct progress_item *next, *prev; /* forward and backward links */
43 void (*render)(struct progress_item */*item*/, /* render function */
44 struct progress_render_state */*rs*/);
46 #define PROGRESS_ITEM_INIT { 0, 0, 0, 0 }
48 extern int progress_init(struct progress_state */*progress*/);
49 extern void progress_free(struct progress_state */*progress*/);
51 extern int progress_clear(struct progress_state */*progress*/);
53 extern int progress_update(struct progress_state */*progress*/);
55 extern int progress_additem(struct progress_state */*progress*/,
56 struct progress_item */*item*/);
58 extern int progress_removeitem(struct progress_state */*progress*/,
59 struct progress_item */*item*/);
62 extern int progress_vputleft(struct progress_render_state */*render*/,
63 const char */*fmt*/, va_list /*ap*/);
65 extern int progress_vputright(struct progress_render_state */*render*/,
66 const char */*fmt*/, va_list /*ap*/);
68 __attribute__((format(printf, 2, 3)))
69 extern int progress_putleft(struct progress_render_state */*render*/,
70 const char */*fmt*/, ...);
72 __attribute__((format(printf, 2, 3)))
73 extern int progress_putright(struct progress_render_state */*render*/,
74 const char */*fmt*/, ...);
76 extern int progress_showbar(struct progress_render_state */*render*/,
79 extern int progress_shownotice(struct progress_render_state */*render*/,
80 int /*bg*/, int /*fg*/);