static void show_lowersubwin(int dore, WINDOW *tsubwin) { int lines, cols; if (dore || COLS != xcols || LINES != xlines) { show_mainwin(1); if (!fullscreen) { if (LINES < 25) lines = LINES - 4 - 3; else lines = 25 - 4 - 3; if (COLS < 82) cols = COLS - 3 - 3; else cols = 80 - 3 - 3; } else { lines = LINES - 2 - 4 - 3; cols = COLS - 2 - 3 - 3; } wresize(tsubwin, lines, cols); mvderwin(tsubwin, 4, 3); } wrefresh(tsubwin); }
// Callback for when Device ID list has been fetched void device_list_fetched() { reset_inactivity_timer(); if (g_device_count == 0) { show_msg("No devices found!", false, 0); hide_mainwin(); } else { if (!showing_mainwin()) show_mainwin(); hide_msg(); g_device_selected = 0; device_details_fetch(g_device_id_list[g_device_selected]); } }
void handle_init(void) { g_device_id_list = NULL; show_mainwin(); show_msg("HomeP\n\nLogging In...", true, 0); comms_register_errorhandler(comms_error); comms_register_devicelist(device_list_fetched); comms_register_devicedetails(device_details_fetched); comms_register_devicestatus(device_status_fetched); comms_register_devicestatusset(device_status_change_sent); ui_register_deviceswitch(device_switched); ui_register_statuschange(device_status_change); reset_inactivity_timer(); // Initializing comms will trigger phone JS to fetch device list init_comms(); }
int main(int argc, char *argv[]) { uint8_t updb_all; int ch; struct stat sb; const char *chrootpath = NULL; setprogname(argv[0]); while ((ch = getopt(argc, argv, "fFgsv")) != -1) { switch (ch) { //case 'f': // force_update = 1; // break; //case 'F': // force_reinstall = 1; // break; case 'v': version(); /* NOTREACHED */ case 's': fullscreen = 1; break; case 'c': chrootpath = optarg; break; case 'g': colouring = 1; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; /* initializations */ initscr(); keypad(stdscr, TRUE); noecho(); cbreak(); /* Size will be overwritten by show_mainwin anyway. */ mainwin = newwin(10, 10, 1, 2); keypad(mainwin, TRUE); if (colouring) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); attron(COLOR_PAIR(1)); bkgd(COLOR_PAIR(1)); wbkgd(mainwin, COLOR_PAIR(1)); wattron(mainwin, COLOR_PAIR(1)); } show_mainwin(1); for (;;) { if (do_menu(main_menu, sizeof(main_menu)/sizeof(struct menuoption), 0, "pkgui")) ask_exit(); } attroff(COLOR_PAIR(1)); endwin(); exit(EXIT_SUCCESS); }
static void main_search(void *arg) { FIELD *mfield[2]; FORM *mform; WINDOW *msubwin; int ch, x, j, i = 0; char *title; char eb[64]; /* Clear screen and print title */ show_mainwin(1); head_mainwin("Search for packages"); msubwin = create_lowersubwin(NULL, &x); if (sizeof keyword < x - 10) x = sizeof keyword; mfield[0] = new_field(1, x - 10, 5, 5, 0, 0); mfield[1] = NULL; set_field_back(mfield[0], A_UNDERLINE); field_opts_off(mfield[0], O_AUTOSKIP); mform = new_form(mfield); set_form_win(mform, mainwin); set_form_sub(mform, msubwin); post_form(mform); show_mainwin(0); keyword[0] = '\0'; while((ch = getch()) != '\n') { switch (ch) { case KEY_LEFT: form_driver(mform, REQ_LEFT_CHAR); i--; break; case KEY_RIGHT: if (keyword[i] != '\0') { form_driver(mform, REQ_RIGHT_CHAR); i++; } break; case KEY_END: form_driver(mform, REQ_END_LINE); i = strlen(keyword); break; case KEY_HOME: form_driver(mform, REQ_BEG_LINE); i = 0; break; case '\b': form_driver(mform, REQ_DEL_PREV); keyword[i] = '\0'; i--; break; default: if (i < sizeof(keyword) - 2) { form_driver(mform, ch); for (j = strlen(keyword); j >= i; j--) keyword[j+1] = keyword[j]; keyword[i] = ch; i++; } break; } show_mainwin(0); } unpost_form(mform); free_form(mform); free_field(mfield[0]); free_field(mfield[1]); if (strlen(keyword) <= 0) return; if ((i = regcomp(&re, keyword, REG_EXTENDED|REG_NOSUB|REG_ICASE)) != 0) { regerror(i, &re, eb, sizeof(eb)); ask_ok("regcomp: %s: %s", keyword, eb); } else { if (asprintf(&title, "Search results for '%s'", keyword) <= 0) { endwin(); err(1, "asprintf"); } //plisthead.P_Plisthead = &r_plisthead; //plisthead.P_count = r_plistcounter; //menu_menupkgs(&plisthead, title, compare_keyword); regfree(&re); free(title); } }
/* * Return codes: * 0 - action performed * -1 - quit was pressed (only for main menu) * +1 - backspace or escape was pressed, back to previous menu */ static int do_menu(struct menuoption *runmenu, int num, int upper, const char *title, ...) { int ch, i, y, x; // char buf[BUFSIZ]; char *buf; struct menuoption *curmenu; ITEM **mitems, *mitem; MENU *mmenu; WINDOW *msubwin; va_list ap; /* Clear screen and print title */ if (upper) show_mainwin(0); else show_mainwin(1); va_start(ap, title); head_mainwin(title, ap); va_end(ap); x = 0; y = 0; if (upper) msubwin = create_uppersubwin(); else msubwin = create_lowersubwin(&y, &x); mitems = (ITEM **)calloc(num + 1, sizeof(ITEM*)); for (curmenu = runmenu, i = 0; i < num; i++) { ch = sizeof buf > x ? x - 1 : sizeof buf - 1; // if (snprintf(buf, ch, "%s", curmenu->m_name) <= 0) { if (asprintf(&buf, "%s", curmenu->m_name) <= 0) { ask_ok("Error creating the menu."); for (i--; i >= 0; i--) free(mitems[i]); return 0; } mitems[i] = new_item(buf, NULL); set_item_userptr(mitems[i], (void *)curmenu); // warnx("%ld %s", (long)curmenu, curmenu->m_name); curmenu++; } mitems[num] = NULL; mmenu = new_menu(mitems); set_menu_win(mmenu, mainwin); set_menu_sub(mmenu, msubwin); set_menu_format(mmenu, upper ? 1 : y, 1); if (colouring) { set_menu_fore(mmenu, COLOR_PAIR(1)); set_menu_back(mmenu, COLOR_PAIR(1)); set_menu_grey(mmenu, COLOR_PAIR(1)); } set_menu_mark(mmenu, ">"); if (post_menu(mmenu)) { ask_ok("Error posting the menu."); return 1; } show_mainwin(0); show_lowersubwin(0, msubwin); while ((ch = getch()) != '\n' && ch != '\b') { switch (ch) { case KEY_DOWN: menu_driver(mmenu, REQ_NEXT_ITEM); break; case KEY_UP: menu_driver(mmenu, REQ_PREV_ITEM); break; case KEY_NPAGE: menu_driver(mmenu, REQ_SCR_DPAGE); break; case KEY_PPAGE: menu_driver(mmenu, REQ_SCR_UPAGE); break; case KEY_END: menu_driver(mmenu, REQ_LAST_ITEM); break; case KEY_HOME: menu_driver(mmenu, REQ_FIRST_ITEM); break; } show_mainwin(0); show_lowersubwin(0, msubwin); } mitem = current_item(mmenu); curmenu = (struct menuoption *)item_userptr(mitem); unpost_menu(mmenu); delwin(msubwin); free_menu(mmenu); for (i = 0; i < num; i++) free_item(mitems[i]); free(mitems); if (ch != '\b' && curmenu->m_action != NULL) { curmenu->m_action(curmenu->m_argv); return 0; } else { return 1; } }
static void exec_cmd_noask(const char *iactstr, const char *icmdstr, ...) { char *actstr, *cmdstr, *tokstr; char **execstr, **runstr; int status, i, fdi, num = 0; char buf[BUFSIZ]; pid_t cpid; va_list ap; WINDOW *msubwin; struct pollfd pfd; va_start(ap, icmdstr); if (vasprintf(&actstr, iactstr, ap) < 0) { endwin(); err(EXIT_FAILURE, "asprintf"); } va_end(ap); va_start(ap, icmdstr); if (vasprintf(&cmdstr, icmdstr, ap) < 0) { endwin(); err(EXIT_FAILURE, "asprintf"); } va_end(ap); show_mainwin(1); head_mainwin(actstr); msubwin = create_lowersubwin(NULL, NULL); cpid = forkpty(&fdi, NULL, NULL, NULL); if (cpid == -1) { endwin(); err(EXIT_FAILURE, "fork"); } else if (cpid == 0) { endwin(); close(STDIN_FILENO); close(STDERR_FILENO); setvbuf(stdout, NULL, _IONBF, 0); /* Convert command string to array */ for (tokstr = cmdstr; *tokstr != '\0'; tokstr++) { if (*tokstr == ' ') num++; } /* 1: We get one less when counting, 2: For NULL termination, 3: For * command name */ execstr = calloc(num + 2, sizeof(char *)); runstr = execstr; for (tokstr = strtok(cmdstr, " "); tokstr != NULL; tokstr = strtok(NULL, " ")) { *runstr = tokstr; runstr++; } execvp(cmdstr, execstr); } else { buf[sizeof(buf) - 1] = '\0'; wprintw(msubwin, "\n"); while (waitpid(cpid, &status, WNOHANG) != cpid) { pfd.fd = fdi; pfd.events = POLLIN; i = poll(&pfd, 1, 100); if (i > 0 && (i = read(fdi, buf, sizeof buf - 2)) > 0) { buf[i] = '\0'; /* If we don't do so, there will be errors displaying stuff. */ for (tokstr = strstr(buf, "\r\n"); tokstr != NULL; tokstr = strstr(tokstr, "\r\n")) { tokstr[0] = '\n'; tokstr[1] = '\r'; } waddstr(msubwin, buf); touchwin(mainwin); wrefresh(msubwin); } } if (!WIFEXITED(status)) ask_ok("Command `%s' failed with signal %d", cmdstr, WEXITSTATUS(status)); else ask_ok(actstr); } delwin(msubwin); free(cmdstr); free(actstr); return; }