示例#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
/*
 * Render the given form (and all of the widgets it contains) in the
 * curses backing store.  Does not cause the form to be displayed.
 */
void
curses_form_draw(struct curses_form *cf)
{
	struct curses_widget *w;
	float sb_factor = 0.0;
	size_t sb_off = 0, sb_size = 0;

	curses_colors_set(cf->win, CURSES_COLORS_NORMAL);
	curses_window_blank(cf->win);

	curses_colors_set(cf->win, CURSES_COLORS_BORDER);
	/* draw_frame(cf->left - 1, cf->top - 1, cf->width + 2, cf->height + 2); */
	wborder(cf->win, 0, 0, 0, 0, 0, 0, 0, 0);

	/*
	 * If the internal dimensions of the form exceed the physical
	 * dimensions, draw scrollbar(s) as appropriate.
	 */
	if (cf->int_height > cf->height) {
		sb_factor = (float)cf->height / (float)cf->int_height;
		sb_size = cf->height * sb_factor;
		if (sb_size == 0) sb_size = 1;
		sb_off = cf->y_offset * sb_factor;
		curses_colors_set(cf->win, CURSES_COLORS_SCROLLAREA);
		mvwvline(cf->win, 1, cf->width + 1, ACS_CKBOARD, cf->height);
		curses_colors_set(cf->win, CURSES_COLORS_SCROLLBAR);
		mvwvline(cf->win, 1 + sb_off, cf->width + 1, ACS_BLOCK, sb_size);
	}

	if (cf->int_width > cf->width) {
		sb_factor = (float)cf->width / (float)cf->int_width;
		sb_size = cf->width * sb_factor;
		if (sb_size == 0) sb_size = 1;
		sb_off = cf->x_offset * sb_factor;
		curses_colors_set(cf->win, CURSES_COLORS_SCROLLAREA);
		mvwhline(cf->win, cf->height + 1, 1, ACS_CKBOARD, cf->width);
		curses_colors_set(cf->win, CURSES_COLORS_SCROLLBAR);
		mvwhline(cf->win, cf->height + 1, 1 + sb_off, ACS_BLOCK, sb_size);
	}

	curses_colors_set(cf->win, CURSES_COLORS_BORDER);

	/*
	 * Render the title bar text.
	 */
	wmove(cf->win, 0, (cf->width - strlen(cf->title)) / 2 - 1);
	waddch(cf->win, ACS_RTEE);
	waddch(cf->win, ' ');
	curses_colors_set(cf->win, CURSES_COLORS_FORMTITLE);
	waddstr(cf->win, cf->title);
	curses_colors_set(cf->win, CURSES_COLORS_BORDER);
	waddch(cf->win, ' ');
	waddch(cf->win, ACS_LTEE);

	/*
	 * Render a "how to get help" reminder.
	 */
	if (cf->help_text != NULL) {
		static const char *help_msg = "Press F1 for Help";

		wmove(cf->win, cf->height + 1,
		      (cf->width - strlen(help_msg)) / 2 - 1);
		waddch(cf->win, ACS_RTEE);
		waddch(cf->win, ' ');
		curses_colors_set(cf->win, CURSES_COLORS_FORMTITLE);
		waddstr(cf->win, help_msg);
		curses_colors_set(cf->win, CURSES_COLORS_BORDER);
		waddch(cf->win, ' ');
		waddch(cf->win, ACS_LTEE);
	}

	/*
	 * Render the widgets.
	 */
	for (w = cf->widget_head; w != NULL; w = w->next) {
		curses_widget_draw(w);
	}

	/* to put the cursor there */
	curses_widget_draw_tooltip(cf->widget_focus);
	curses_widget_draw(cf->widget_focus);
}