static void show_progress(char *line) { dialog_busy(5, 60, line); #if 0 static int nfiles = 0, cfile = 0; static char value[64]; char prompt[64]; if (!strncmp(line, "Running gpart on", 16)) { dialog_busy(5, 60, "Partitioning and labeling disk..."); } else if (!strcmp(line, "pc-sysinstall: Extraction Finished")) { screen_clear(MODULE); dialog_busy(5, 60, "Finishing installation..."); } else if (!strncmp(line, "Cleaning up", 11)) { dialog_busy(5, 60, "Cleaning up disk..."); } else if (!strncmp(line, "NEWFS:", 6)) { strlcpy(value, line+7, sizeof(value)); snprintf(prompt, sizeof(prompt), "Creating filesystem %s", value); dialog_busy(5, 60, prompt); } else if (!strncmp(line, "FETCH:", 6)) { screen_clear(MODULE); dialog_busy(5, 60, "Preparing to fetch..."); strlcpy(value, basename(line+6), sizeof(value)); } else if (!strncmp(line, "SIZE:", 5)) { int size, down; sscanf(line, "SIZE: %u DOWNLOADED: %u", &size, &down); if (down == 0) down = 1; if (size == 0) size = 1; if (down > size) down = size; snprintf(prompt, sizeof(prompt), "Downloading file %s", value); dialog_gauge("File download", prompt, (LINES - 7) / 2, (COLS - 60) / 2, 7, 60, (down * 100) / size); } else if (!strncmp(line, "INSTALLCOUNT:", 13)) { nfiles = atoi(line+14); cfile = 0; /* XXX we should be using a FSM */ } else if (!strncmp(line, "x ", 2)) { cfile++; snprintf(prompt, sizeof(prompt), "%s", line + 3); dialog_gauge("Installation progress", prompt, (LINES - 7) / 2, (COLS - 60) / 2, 7, 60, (cfile * 100) / nfiles); } #endif }
static int _menu1_sa_action(dialogMenuItem * self) { int ret; dialog_clear(); dialog_msgbox("ClosedBSD", "Please insert a floppy diskette and press a key.", -1, -1, 1); dialog_clear(); if ((ret = system("/sbin/mount /dev/fd0 /mnt")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "This floppy is not formatted. Press a key to format. (This may take a few minutes)", -1, -1, 1); dialog_clear(); dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 10); if ((ret = system("/sbin/fdformat -y /dev/fd0 >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Some error occured during 'fdformat'. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 30); if ((ret = system("/sbin/disklabel -w -r /dev/fd0 fd1440 >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Some error occured during 'disklabel'. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 60); if ((ret = system("/sbin/newfs -T fd1440 /dev/fd0 fd1440 >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Some error occured during 'newfs'. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 100); if ((ret = system("/sbin/mount /dev/fd0 /mnt >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Unable to mount floppy. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } system("/sbin/writetcnp"); } else system("/sbin/umount /dev/fd0"); system("/sbin/writetcnp"); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
static int j_gauge(JUMPARGS) { *offset_add = arg_rest(av); return dialog_gauge(t, av[1], numeric_arg(av, 2), numeric_arg(av, 3), optional_num(av, 4, 0)); }
/* Kick it off, James! */ int main(int argc, char **argv) { int i; init_dialog(); for (i = 0; i <= 100; i++) { dialog_gauge("Gas tank", "When this gets 100% full, you'd better yank out the nozzle!", 10, 1, 7, 70, i); usleep(30000); } end_dialog(); return 0; }
void /* ANSI C can bite me */ main() { int rc; char result[20]; int sc=0, ch=0; extern int LINES, COLS; init_dialog(); while (1) { rc = dialog_menu(0, "Choose a dialog function to test", LINES-2, COLS-2, NRCHOICES, NRCHOICES, choices, result, &sc, &ch); if (rc != 0) break; if (strstr(result, "menu")) { int sc2=0, ch2=0; rc = dialog_menu("menu", "menu box", -1, -1, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); sc2=0, ch2=0; rc = dialog_menu("menu", "menu box\nnumber 2", 13, 35, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"check")) { rc = dialog_checklist("checklist", "checklist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"radio")) { rc = dialog_radiolist("radiolist", "radiolist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result, "notify")) dialog_notify("A Notification box"); else if (strstr(result, "msg")) { dialog_msgbox("msgbox", "Sleeping 2 seconds on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "Sleeping 1 second on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "A msg box that wants user input", -1, -1, 1); } else if (strstr(result, "mesg")) dialog_mesgbox("mesgbox", "A mesg box", -1, -1); else if (strstr(result, "yesno")) { rc = dialog_yesno("yesno", "Test me\nPress YES or NO", -1, -1); if (rc == 0) dialog_notify("You pressed YES"); else if (rc > 0) dialog_notify("You pressed NO"); else dialog_notify("Something Wicked Happened!"); } else if (strstr(result, "gauge")) { int x; for (x=0; x<=20; x++) { dialog_gauge("test", "gauge", -1, -1, -1, 40, x*5); usleep(300000); } } } end_dialog(); exit((rc < 0) ? 1 : 0); }