static bool handle_input(DIALOG_CALLBACK * cb) { MY_OBJ *obj = (MY_OBJ *) cb; bool result; int status; char buf[MY_LEN]; if (dialog_state.pipe_input == 0) { status = -1; } else if ((status = read_data(buf, dialog_state.pipe_input)) > 0) { if (isMarker(buf)) { /* * Historically, next line should be percentage, but one of the * worse-written clones of 'dialog' assumes the number is missing. * (Gresham's Law applied to software). */ if ((status = read_data(buf, dialog_state.pipe_input)) > 0) { obj->prompt_buf[0] = '\0'; if (decode_percent(buf)) obj->percent = atoi(buf); else strcpy(obj->prompt_buf, buf); /* Rest is message text */ while ((status = read_data(buf, dialog_state.pipe_input)) > 0 && !isMarker(buf)) { if (strlen(obj->prompt_buf) + strlen(buf) < sizeof(obj->prompt_buf) - 1) { strcat(obj->prompt_buf, buf); } } if (obj->prompt != obj->prompt_buf) free(obj->prompt); obj->prompt = obj->prompt_buf; } } else if (decode_percent(buf)) { obj->percent = atoi(buf); } } else { if (feof(dialog_state.pipe_input) || (ferror(dialog_state.pipe_input) && errno != EINTR)) { delink(obj); dlg_remove_callback(cb); } } if (status > 0) { result = TRUE; repaint_text(obj); } else { result = FALSE; } return result; }
static bool handle_my_getc(DIALOG_CALLBACK * cb, int ch, int fkey, int *result) { MY_OBJ *obj = (MY_OBJ *) cb; bool done = FALSE; if (!fkey && dlg_char_to_button(ch, obj->buttons) == 0) { ch = DLGK_ENTER; fkey = TRUE; } if (fkey) { switch (ch) { case DLGK_ENTER: *result = DLG_EXIT_OK; done = TRUE; break; case DLGK_BEGIN: /* Beginning of line */ obj->hscroll = 0; break; case DLGK_GRID_LEFT: /* Scroll left */ if (obj->hscroll > 0) { obj->hscroll -= 1; } break; case DLGK_GRID_RIGHT: /* Scroll right */ if (obj->hscroll < MAX_LEN) obj->hscroll += 1; break; default: beep(); break; } if ((obj->hscroll != obj->old_hscroll)) repaint_text(obj); } else { switch (ch) { case ERR: clearerr(cb->input); ch = getc(cb->input); (void) ungetc(ch, cb->input); if (ch != EOF) { handle_input(cb); } break; case ESC: done = TRUE; *result = DLG_EXIT_ESC; break; default: beep(); break; } } return !done; }
void dlg_update_gauge(void *objptr, int percent) { MY_OBJ *obj = (MY_OBJ *) objptr; curs_set(0); obj->percent = percent; repaint_text(obj); }
static bool handle_input(DIALOG_CALLBACK * cb) { MY_OBJ *obj = (MY_OBJ *) cb; FILE *fp = obj->obj.input; struct stat sb; if (fstat(fileno(fp), &sb) == 0 && sb.st_size != obj->last_pos) { repaint_text(obj); } return TRUE; }
/* * 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; }