/* * 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); /* avoid breaking new window in dlg_remove_callback */ oldobj->obj.caller = 0; oldobj->obj.input = 0; oldobj->obj.keep_win = FALSE; /* remove the old version of the gauge */ 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 text from a file in a dialog box, like in a "tail -f". */ int dialog_tailbox(const char *title, const char *file, int height, int width, int bg_task) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, DLG_KEYS_DATA( DLGK_BEGIN, '0' ), DLG_KEYS_DATA( DLGK_BEGIN, KEY_BEG ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'H' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'h' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, KEY_LEFT ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ), END_KEYS_BINDING }; /* *INDENT-ON* */ #ifdef KEY_RESIZE int old_height = height; int old_width = width; #endif int fkey; int x, y, result, thigh; WINDOW *dialog, *text; const char **buttons = 0; MY_OBJ *obj; FILE *fd; int min_width = 12; /* Open input file for reading */ if ((fd = fopen(file, "rb")) == NULL) dlg_exiterr("Can't open input file in dialog_tailbox()."); #ifdef KEY_RESIZE retry: #endif dlg_auto_sizefile(title, file, &height, &width, 2, min_width); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); thigh = height - ((2 * MARGIN) + (bg_task ? 0 : 2)); dialog = dlg_new_window(height, width, y, x); dlg_mouse_setbase(x, y); /* Create window for text region, used for scrolling text */ text = dlg_sub_window(dialog, thigh, width - (2 * MARGIN), y + MARGIN, x + MARGIN); dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); dlg_draw_bottom_box(dialog); dlg_draw_title(dialog, title); dlg_draw_helpline(dialog, FALSE); if (!bg_task) { buttons = dlg_exit_label(); dlg_button_layout(buttons, &min_width); dlg_draw_buttons(dialog, height - (2 * MARGIN), 0, buttons, FALSE, FALSE, width); } (void) wmove(dialog, thigh, (MARGIN + 1)); (void) wnoutrefresh(dialog); obj = dlg_calloc(MY_OBJ, 1); assert_ptr(obj, "dialog_tailbox"); obj->obj.input = fd; obj->obj.win = dialog; obj->obj.handle_getc = handle_my_getc; obj->obj.handle_input = bg_task ? handle_input : 0; obj->obj.keep_bg = bg_task && dialog_vars.cant_kill; obj->obj.bg_task = bg_task; obj->text = text; obj->buttons = buttons; dlg_add_callback(&(obj->obj)); dlg_register_window(dialog, "tailbox", binding); dlg_register_buttons(dialog, "tailbox", buttons); /* Print last page of text */ dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr); repaint_text(obj); if (bg_task) { result = DLG_EXIT_OK; } else { int ch; do { ch = dlg_getc(dialog, &fkey); #ifdef KEY_RESIZE if (fkey && ch == KEY_RESIZE) { /* reset data */ height = old_height; width = old_width; /* repaint */ dlg_clear(); dlg_del_window(dialog); refresh(); dlg_mouse_free_regions(); dlg_button_layout(buttons, &min_width); goto retry; } #endif } while (handle_my_getc(&(obj->obj), ch, fkey, &result)); } dlg_mouse_free_regions(); return result; }