17959Sache/*
27959Sache * gauge.c
37959Sache *
47959Sache * progress indicator for libdialog
57959Sache *
67959Sache *
77959Sache * Copyright (c) 1995, Marc van Kempen
87959Sache *
97959Sache * All rights reserved.
107959Sache *
117959Sache * This software may be used, modified, copied, distributed, and
127959Sache * sold, in both source and binary form provided that the above
137959Sache * copyright and these terms are retained, verbatim, as the first
147959Sache * lines of this file.  Under no circumstances is the author
157959Sache * responsible for the proper functioning of this software, nor does
167959Sache * the author assume any responsibility for damages incurred with
177959Sache * its use.
187959Sache */
197959Sache
2087087Sru#include <sys/cdefs.h>
2187087Sru__FBSDID("$FreeBSD$");
2287087Sru
2397623Swollman#include <stdlib.h>
24103140Swollman#include <string.h>
2597623Swollman
267959Sache#include "dialog.h"
277959Sache
287959Sachevoid
298858Srgrimesdialog_gauge(char *title, char *prompt, int y, int x,
307959Sache	     int height, int width, int perc)
317959Sache/*
327959Sache * Desc: display a progress bar, progress indicated by <perc>
337959Sache */
347959Sache{
357959Sache    WINDOW 	*gw;
367959Sache    int		glen, i;
377959Sache    char	percs[5];
387959Sache
397959Sache    gw = newwin(height, width, y, x);
407959Sache    if (!gw) {
417959Sache	fprintf(stderr, "dialog_gauge: Error creating window (%d, %d, %d, %d)",
427959Sache		height, width, y, x);
437959Sache	exit(-1);
447959Sache    }
458858Srgrimes
467959Sache    draw_box(gw, 0, 0, height, width, dialog_attr, border_attr);
477959Sache    draw_shadow(stdscr, y, x, height, width);
487959Sache
497959Sache    wattrset(gw, title_attr);
507959Sache    if (title) {
517959Sache	wmove(gw, 0, (width - strlen(title))/2 - 1);
527959Sache	waddstr(gw, "[ ");
537959Sache	waddstr(gw, title);
547959Sache	waddstr(gw, " ]");
557959Sache    }
567959Sache    wattrset(gw, dialog_attr);
577959Sache    if (prompt) {
587959Sache	wmove(gw, 1, (width - strlen(prompt))/2 - 1);
597959Sache	waddstr(gw, prompt);
607959Sache    }
617959Sache
627959Sache    draw_box(gw, 2, 2, 3, width-4, dialog_attr, border_attr);
637959Sache    glen = (int) ((float) perc/100 * (width-6));
647959Sache
657959Sache    wattrset(gw, dialog_attr);
667959Sache    sprintf(percs, "%3d%%", perc);
677959Sache    wmove(gw, 5, width/2 - 2);
687959Sache    waddstr(gw, percs);
697959Sache
707959Sache    wattrset(gw, A_BOLD);
717959Sache    wmove(gw, 3, 3);
727959Sache    for (i=0; i<glen; i++) waddch(gw, ' ');
737959Sache
747959Sache    wrefresh(gw);
7587087Sru    delwin(gw);
767959Sache
777959Sache    return;
787959Sache} /* dialog_gauge() */
798858Srgrimes
80