1 /*
2 * gauge.c
3 *
4 * progress indicator for libdialog
5 *
6 *
7 * Copyright (c) 1995, Marc van Kempen
8 *
9 * All rights reserved.
10 *
11 * This software may be used, modified, copied, distributed, and
12 * sold, in both source and binary form provided that the above
13 * copyright and these terms are retained, verbatim, as the first
14 * lines of this file. Under no circumstances is the author
15 * responsible for the proper functioning of this software, nor does
16 * the author assume any responsibility for damages incurred with
17 * its use.
18 */
19
20 #include <sys/cdefs.h>
21 __FBSDID("$FreeBSD: stable/9/gnu/lib/libodialog/gauge.c 103140 2002-09-09 17:44:08Z wollman $");
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "dialog.h"
27
28 void
dialog_gauge(char * title,char * prompt,int y,int x,int height,int width,int perc)29 dialog_gauge(char *title, char *prompt, int y, int x,
30 int height, int width, int perc)
31 /*
32 * Desc: display a progress bar, progress indicated by <perc>
33 */
34 {
35 WINDOW *gw;
36 int glen, i;
37 char percs[5];
38
39 gw = newwin(height, width, y, x);
40 if (!gw) {
41 fprintf(stderr, "dialog_gauge: Error creating window (%d, %d, %d, %d)",
42 height, width, y, x);
43 exit(-1);
44 }
45
46 draw_box(gw, 0, 0, height, width, dialog_attr, border_attr);
47 draw_shadow(stdscr, y, x, height, width);
48
49 wattrset(gw, title_attr);
50 if (title) {
51 wmove(gw, 0, (width - strlen(title))/2 - 1);
52 waddstr(gw, "[ ");
53 waddstr(gw, title);
54 waddstr(gw, " ]");
55 }
56 wattrset(gw, dialog_attr);
57 if (prompt) {
58 wmove(gw, 1, (width - strlen(prompt))/2 - 1);
59 waddstr(gw, prompt);
60 }
61
62 draw_box(gw, 2, 2, 3, width-4, dialog_attr, border_attr);
63 glen = (int) ((float) perc/100 * (width-6));
64
65 wattrset(gw, dialog_attr);
66 sprintf(percs, "%3d%%", perc);
67 wmove(gw, 5, width/2 - 2);
68 waddstr(gw, percs);
69
70 wattrset(gw, A_BOLD);
71 wmove(gw, 3, 3);
72 for (i=0; i<glen; i++) waddch(gw, ' ');
73
74 wrefresh(gw);
75 delwin(gw);
76
77 return;
78 } /* dialog_gauge() */
79
80