/* * Display a dialog box and get the search term from user */ static int get_search_term(WINDOW *win, unsigned char *search_term, int height, int width) { int x, y, key = 0, first, box_height = 3, box_width = 30; x = (width - box_width)/2; y = (height - box_height)/2; #ifdef HAVE_NCURSES if (use_shadow) draw_shadow(win, y, x, box_height, box_width); #endif draw_box(win, y, x, box_height, box_width, dialog_attr, searchbox_border_attr); wattrset(win, searchbox_title_attr); wmove(win, y, x+box_width/2-4); waddstr(win, " Search "); wattrset(win, dialog_attr); search_term[0] = '\0'; first = 1; while (key != ESC) { key = line_edit(win, y+1, x+1, -1, box_width-2, searchbox_attr, first, search_term, 0); first = 0; switch (key) { case '\n': if (search_term[0] != '\0') return 0; break; case ESC: break; } } return -1; /* ESC pressed */ }
t_nb_status nb_get_line(const char *prompt, char **line) { t_nboon l; int ret; if (nb_enable_raw(STDIN_FILENO) == -1) return (NB_ERROR); init_line(&l); l.p_cursor = get_str_display_width(prompt); l.p_len = expand_prompt(prompt, &l.prompt); l.nbr_rows = 0; nb_refresh_size(0); ret = line_edit(&l); nb_disable_raw(l.fd); free(l.prompt); free(l.paste_line); free(l.save_line); write(l.fd, "\n", 1); *line = ((ret != NB_EXIT) ? nb_strdup(l.buf) : NULL); return (ret); }
int ifs_cfg(char *title, char *prompt, int height, int width, int y, int x, char *dev) { WINDOW *w; int i, n, k, j; char titlez[80]; char devz[80]; int foo, done, key, set; struct device d; int ret = -1; int dev_id; init_dialog(); dialog_clear(); draw_shadow(stdscr, y, x, height, width); w = newwin(height, width, y, x); draw_box(w, 0, 0, height, width, dialog_attr, border_attr); wattrset(w, border_attr); keypad(w, TRUE); /* draw pretty lines outside. */ /* box(w, ACS_VLINE, ACS_HLINE); */ wrefresh(w); snprintf(titlez, sizeof(titlez), " [ %s ] ", title); foo = ((width / 2) - strlen(title)); wmove(w, 0, foo); wattrset(w, title_attr); waddstr(w, titlez); wattrset(w, border_attr); for (i = 1; i < (height - 1); i++) { for (n = 1; n < (width - 1); n++) { wmove(w, i, n); waddch(w, ' '); } } draw_box(w, 2, 3, 12, 44, dialog_attr, border_attr); wattrset(w, title_attr); wmove(w, 4, 4); waddstr(w, " IP ->"); draw_box(w, 3, 18, 3, 25, dialog_attr, border_attr); wattrset(w, title_attr); wmove(w, 7, 4); waddstr(w, " Netmask ->"); draw_box(w, 6, 18, 3, 25, dialog_attr, border_attr); wattrset(w, title_attr); wmove(w, 10, 4); waddstr(w, " Gateway ->"); draw_box(w, 9, 18, 3, 25, dialog_attr, border_attr); print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); d.dhcp = DHCP_DISABLED; if ((ret = device_exist(dev)) >= 0) { wattrset(w, dialog_attr); wrefresh(w); /* fill in the previously configured values */ snprintf(d.ip, sizeof(d.ip), "%s", dev_ip(dev)); if (strlen(d.ip) > 6) mvwprintw(w, 4, 19, "%s", d.ip); else bzero(d.ip, sizeof(d.ip)); snprintf(d.netmask, sizeof(d.netmask), "%s", dev_netmask(dev)); if (strlen(d.netmask) > 6) mvwprintw(w, 7, 19, "%s", d.netmask); else bzero(d.netmask, sizeof(d.netmask)); snprintf(d.gateway, sizeof(d.gateway), "%s", dev_gateway(dev)); if (strlen(d.gateway) > 6) mvwprintw(w, 10, 19, "%s", d.gateway); else bzero(d.gateway, sizeof(d.gateway)); snprintf(devz, sizeof(devz), "Editing device %s", dev); wmove(w, 1, (width / 2) - (strlen(devz) / 2)); wattrset(w, dialog_attr); waddstr(w, devz); wrefresh(w); } else { bzero(d.ip, sizeof(d.ip)); bzero(d.netmask, sizeof(d.netmask)); bzero(d.gateway, sizeof(d.gateway)); snprintf(devz, sizeof(devz), "Configuring device %s", dev); wmove(w, 1, (width / 2) - (strlen(devz) / 2)); wattrset(w, dialog_attr); waddstr(w, devz); } /* start off in first window. */ done = key = set = 0; j = 1; while (!done) { wrefresh(w); switch (j) { case 1: wattrset(w, inputbox_attr); wrefresh(w); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE); if (strlen(d.ip) < 1) bzero(d.ip, sizeof(d.ip)); k = line_edit(w, 4, 19, 23, 23, inputbox_attr, 1, d.ip, DialogInputAttrs); if (k == KEY_DOWN) { j++; break; } else if (k == 9) { j++; break; } else if (k == KEY_UP) { j = 1; break; } else if (k == 10) { j++; break; } break; case 2: wattrset(w, inputbox_attr); wrefresh(w); /* * print_button(w, " OK * ",height-2,(width/2)-11,FALSE); */ if (strlen(d.netmask) < 1) bzero(d.netmask, sizeof(d.netmask)); k = line_edit(w, 7, 19, 23, 23, inputbox_attr, 1, d.netmask, DialogInputAttrs); if (k == KEY_DOWN) { j++; break; } else if (k == 10) { j++; break; } else if (k == 9) { j++; break; } else if (k == KEY_UP) { j = 1; break; } break; case 3: wattrset(w, inputbox_attr); wrefresh(w); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); if (strlen(d.gateway) < 1) bzero(d.gateway, sizeof(d.gateway)); k = line_edit(w, 10, 19, 23, 23, inputbox_attr, 1, d.gateway, DialogInputAttrs); if (k == KEY_DOWN) { j++; break; } else if (k == 10) { j++; break; } else if (k == 9) { j++; break; } else if (k == KEY_UP) { j--; break; } break; case 4: wattrset(w, title_attr); wrefresh(w); curs_set(0); print_button(w, " OK ", height - 2, (width / 2) - 11, TRUE); print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE); wrefresh(w); key = wgetch(w); if (key == KEY_UP) { j--; break; } else if (key == 9) { j++; break; } else if (key == KEY_DOWN) { j++; break; } else if (key == 10) { done = 1; set = 1; break; } break; case 5: wattrset(w, title_attr); wrefresh(w); curs_set(0); print_button(w, " OK ", height - 2, (width / 2) - 11, FALSE); print_button(w, "Cancel", height - 2, (width / 2) + 3, TRUE); wrefresh(w); key = wgetch(w); if (key == KEY_UP) { j = 4; break; } else if (key == KEY_DOWN) { j = 4; break; } else if (key == 9) { j = 1; break; } else if (key == 10) { dialog_clear(); return -1; break; } break; } } if (strlen(d.gateway) > 1) { ret = dialog_yesno("ClosedBSD", "Would you like this device to be the default gateway?", -1, -1); if (ret == 0) { if ((ext_exist()) == -1) { d.ext = 1; } else { dialog_clear(); ret = dialog_yesno("ClosedBSD", "You already have a default gateway set. Overwrite?", -1, -1); if (ret == 0) { unset_ext(d.id); } else { d.ext = 0; } } } else { d.ext = 0; } } else d.ext = 0; strcpy(d.device, dev); if (set == 1) { dialog_clear(); dev_id = device_exist(d.device); switch (dev_id) { case -1: d.id = next_device_id(); insert_device(d); break; default: ret = dialog_yesno("ClosedBSD", "This device is already configured. Overwrite?", -1, -1); if (ret == 0) { d.id = dev_id; insert_device(d); break; } else { break; } } } dialog_clear(); wrefresh(w); end_dialog(); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
/* getfullline(): * Basic line retrieval; but with a few options... * This function is accessed through the getline_xx functions * below. * Args... * buf: pointer to buffer to be used to place the incoming characters. * max: size of the buffer. * ledit: if set, then allow the line-editor to be used if ESC is input. * timeout: if positive, then after 'timeout' number of seconds waiting * per character, giveup. * if negative, then after 'timeout' number of seconds waiting * total, giveup. * if zero, then wait forever. * prefill: if set, prefill the buffer with that string and show the user. * echo: if set, characters are echoed as they are entered. */ int getfullline(char *buf,int max,int ledit, int timeout,char *prefill, int echo) { char *base; struct elapsed_tmr tmr; static unsigned char crlf; int tot, idx, cumulativetimeout; cumulativetimeout = 0; tot = idx = 0; base = buf; max -= 1; /* Make sure there is space for the null terminator. */ if (prefill) { strcpy(base,prefill); tot = strlen(prefill); putstr(prefill); buf += tot; idx = tot; } /* If the timeout parameter is negative, then assume that this is * to be run with a cumulative timeout rather than a timeout that * is re-started after each character... */ if (timeout < 0) { cumulativetimeout = 1; timeout = abs(timeout); } for(;idx<max;idx++) { if (timeout > 0) { startElapsedTimer(&tmr,timeout); while(!msecElapsed(&tmr)) { if (gotachar()) break; pollethernet(); } if (cumulativetimeout) timeout = msecRemaining(&tmr); if (ELAPSED_TIMEOUT(&tmr)) { *buf = 0; return(-1); /* Return negative to indicate timeout */ } } if (cumulativetimeout && timeout == 0) { *buf = 0; return(-1); } *buf = (char)getchar(); if (!*buf) { idx--; continue; } #if INCLUDE_LINEEDIT if ((*buf == 0x1b) && (ledit)) { (void)line_edit(base); break; } else #endif { if ((*buf == '\r') || (*buf == '\n')) { if ((crlf) && (*buf != crlf)) { crlf = 0; continue; } #if UMON_TARGET == UMON_TARGET_XT || UMON_TARGET == UMON_TARGET_ARM // use CR/LF puts("\r"); #else putchar('\n'); #endif crlf = *buf; *buf = 0; break; } if (*buf == '\b') { if (tot) { idx -= 2; buf--; tot--; if (echo) putstr("\b \b"); } } else if (*buf == CTLC) { puts("^C"); *base = 0; return(0); } else { if (echo) putchar(*buf); tot++; buf++; } crlf = 0; } } if (idx == max) { printf((char *)"\007\nInput too long (exceeds %d bytes).\n",max); *buf = 0; return(0); } #if INCLUDE_LINEEDIT if (ledit) historylog(base); #endif return(strlen(base)); }