FreeBSD/contrib/dialog/guage.c
/*
 * Display a gauge, or progress meter.  Starts at percent% and reads stdin.  If
 * stdin is not XXX, then it is interpreted as a percentage, and the display is
 * updated accordingly.  Otherwise the next line is the percentage, and
 * subsequent lines up to another XXX are used for the new prompt.  Note that
 * the size of the window never changes, so the prompt can not get any larger
 * than the height and width specified.
 */
Display a gauge, or progress meter.  Starts at percent% and reads stdin.  If
stdin is not XXX, then it is interpreted as a percentage, and the display is
updated accordingly.  Otherwise the next line is the percentage, and
subsequent lines up to another XXX are used for the new prompt.  Note that
the size of the window never changes, so the prompt can not get any larger
than the height and width specified.
Display a gauge or progress meter . Starts at percent% and reads stdin . If stdin is not XXX then it is interpreted as a percentage and the display is updated accordingly . Otherwise the next line is the percentage and subsequent lines up to another XXX are used for the new prompt . Note that the size of the window never changes so the prompt can not get any larger than the height and width specified .
int
dialog_gauge(const char *title,
	     const char *cprompt,
	     int height,
	     int width,
	     int percent)
{
    int fkey;
    int ch, result;
    void *objptr = dlg_allocate_gauge(title, cprompt, height, width, percent);
    MY_OBJ *obj = (MY_OBJ *) objptr;
    dlg_add_callback_ref((DIALOG_CALLBACK **) & obj, my_cleanup);
    dlg_update_gauge(obj, percent);
    dlg_trace_win(obj->obj.win);
    do {
	ch = dlg_getc(obj->obj.win, &fkey);
#ifdef KEY_RESIZE
	if (fkey && ch == KEY_RESIZE) {
	    MY_OBJ *oldobj = obj;
	    dlg_mouse_free_regions();
	    obj = dlg_allocate_gauge(title,
				     cprompt,
				     height,
				     width,
				     oldobj->percent);
	    oldobj->obj.caller = 0;
	    oldobj->obj.input = 0;
	    oldobj->obj.keep_win = FALSE;
	    dlg_clear();
	    dlg_remove_callback(&(oldobj->obj));
	    refresh();
	    dlg_add_callback_ref((DIALOG_CALLBACK **) & obj, my_cleanup);
	    dlg_update_gauge(obj, obj->percent);
	}
#endif
    }
    while (valid(obj) && handle_my_getc(&(obj->obj), ch, fkey, &result));
    dlg_free_gauge(obj);
    return (DLG_EXIT_OK);
}
int dialog_gauge ( const char * title , const char * cprompt , int height , int width , int percent ) { int fkey ; int ch , result ; void * objptr = dlg_allocate_gauge ( title , cprompt , height , width , percent ) ; MY_OBJ * obj = ( MY_OBJ * ) objptr ; dlg_add_callback_ref ( ( DIALOG_CALLBACK * * ) & obj , my_cleanup ) ; dlg_update_gauge ( obj , percent ) ; dlg_trace_win ( obj -> obj . win ) ; do { ch = dlg_getc ( obj -> obj . win , & fkey ) ; #ifdef KEY_RESIZE if ( fkey && ch == KEY_RESIZE ) { MY_OBJ * oldobj = obj ; dlg_mouse_free_regions ( ) ; obj = dlg_allocate_gauge ( title , cprompt , height , width , oldobj -> percent ) ; oldobj -> obj . caller = 0 ; oldobj -> obj . input = 0 ; oldobj -> obj . keep_win = FALSE ; dlg_clear ( ) ; dlg_remove_callback ( & ( oldobj -> obj ) ) ; refresh ( ) ; dlg_add_callback_ref ( ( DIALOG_CALLBACK * * ) & obj , my_cleanup ) ; dlg_update_gauge ( obj , obj -> percent ) ; } #endif } while ( valid ( obj ) && handle_my_getc ( & ( obj -> obj ) , ch , fkey , & result ) ) ; dlg_free_gauge ( obj ) ; return ( DLG_EXIT_OK ) ; }
Display a gauge, or progress meter.
Display a gauge or progress meter .
/* avoid breaking new window in dlg_remove_callback */ /* remove the old version of the gauge */