예제 #1
0
void
curses_widgets_update_from_dfui_progress(const struct dfui_progress *pr,
					 struct curses_widget *pbar,
					 struct curses_widget *plab,
					 struct curses_widget *pcan)
{
	const char *short_desc;
	struct timeval now;
	long msec_diff;
	struct curses_widget *w;
	int short_desc_changed;

	gettimeofday(&now, NULL);
	msec_diff = (now.tv_sec - last_update.tv_sec) * 1000 +
		    (now.tv_usec - last_update.tv_usec) / 1000;

	short_desc = dfui_info_get_short_desc(dfui_progress_get_info(pr));
	short_desc_changed = (strncmp(plab->text, short_desc, MIN(55, strlen(short_desc))) != 0);

	if (msec_diff < 100 && !dfui_progress_get_streaming(pr) && !short_desc_changed)
		return;

	if (dfui_progress_get_amount(pr) != pbar->amount ||
	    short_desc_changed ||
	    dfui_progress_get_streaming(pr)) {
		strcpy_max(plab->text, short_desc, 58);
		curses_widget_draw(plab);
		pbar->amount = dfui_progress_get_amount(pr);
		curses_widget_draw(pbar);
		if (dfui_progress_get_streaming(pr)) {
			/* add a label with the text */
			w = curses_form_widget_add(pbar->form, 0, ++last_y, 58,
			    CURSES_LABEL, FIFTY_EIGHT_SPACES, 0, CURSES_WIDGET_CENTER);
			strcpy_max(w->text, dfui_progress_get_msg_line(pr), 58);
			if (last_y >= pbar->form->int_height) {
				pbar->form->int_height = last_y + 1;
			}
			curses_form_widget_ensure_visible(w);
			curses_widget_draw(w);
		}
	} else {
		curses_progress_spin(pbar);
	}
	wmove(pcan->form->win, pcan->y + 1, pcan->x + pcan->width + 1);
	curses_form_refresh(NULL);
	last_update = now;
}
예제 #2
0
struct curses_form *
curses_form_construct_from_dfui_progress(const struct dfui_progress *pr,
					 struct curses_widget **pbar,
					 struct curses_widget **plab,
					 struct curses_widget **pcan)
{
	struct curses_form *cf;
	const char *desc;

	desc = dfui_info_get_short_desc(dfui_progress_get_info(pr));

	cf = curses_form_new(dfui_info_get_name(dfui_progress_get_info(pr)));

	cf->width = 60;
	cf->height = 6;

	if (dfui_progress_get_streaming(pr)) {
		cf->height = 20;
	}

	*plab = curses_form_widget_add(cf, 0, 1, 58,
	    CURSES_LABEL, FIFTY_EIGHT_SPACES, 0, CURSES_WIDGET_CENTER);
	strcpy_max((*plab)->text, desc, 58);
	*pbar = curses_form_widget_add(cf, 0, 3, 40,
	    CURSES_PROGRESS, "", 0, CURSES_WIDGET_CENTER);
	*pcan = curses_form_widget_add(cf, 0, 5, 0,
	    CURSES_BUTTON, "Cancel", 0,
	    CURSES_WIDGET_CENTER | CURSES_WIDGET_WIDEN);
	(*pbar)->amount = dfui_progress_get_amount(pr);

	last_y = (*pbar)->y + 2;

	curses_form_finalize(cf);

	gettimeofday(&last_update, NULL);

	return(cf);
}
예제 #3
0
static void
show_progress(struct dfui_progress *pr)
{
	printf("  %d%c done...\n", dfui_progress_get_amount(pr), '%');
}