/* * Display a menu for choosing among a number of options */ int dialog_menu(const char *title, const char *prompt, int height, int width, int menu_height, const char *current, int item_no, const char *const *items) { int i, j, x, y, box_x, box_y; int key = 0, button = 0, scroll = 0, choice = 0; int first_item = 0, max_choice; WINDOW *dialog, *menu; FILE *f; max_choice = MIN(menu_height, item_no); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset(dialog, border_attr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dialog_attr); wbkgdset(dialog, dialog_attr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); menu_width = width - 6; box_y = height - menu_height - 5; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); keypad(menu, TRUE); /* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, menubox_border_attr, menubox_attr); item_x = (menu_width - 70) / 2; /* Set choice to default item */ for (i = 0; i < item_no; i++) if (strcmp(current, items[i * 2]) == 0) choice = i; /* get the scroll info from the temp file */ if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && (scroll + max_choice > choice) && (scroll >= 0) && (scroll + max_choice <= item_no)) { first_item = scroll; choice = choice - scroll; fclose(f); } else { scroll = 0; remove("lxdialog.scrltmp"); fclose(f); f = NULL; } } if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { if (choice >= item_no - max_choice / 2) scroll = first_item = item_no - max_choice; else scroll = first_item = choice - max_choice / 2; choice = choice - scroll; } /* Print the menu */ for (i = 0; i < max_choice; i++) { print_item(first_item + i, i, i == choice); } wnoutrefresh(menu); print_arrows(dialog, item_no, scroll, box_y, box_x + item_x + 1, menu_height); print_buttons(dialog, height, width, 0); wmove(menu, choice, item_x + 1); wrefresh(menu); while (key != ESC) { key = wgetch(menu); if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynmh", key)) i = max_choice; else { for (i = choice + 1; i < max_choice; i++) { j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); if (key == tolower(items[(scroll + i) * 2 + 1][j])) break; } if (i == max_choice) for (i = 0; i < max_choice; i++) { j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); if (key == tolower(items[(scroll + i) * 2 + 1][j])) break; } } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { /* Remove highligt of current item */ print_item(scroll + choice, choice, FALSE); if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { /* Scroll menu down */ do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else choice = MAX(choice - 1, 0); } else if (key == KEY_DOWN || key == '+') { print_item(scroll+choice, choice, FALSE); if ((choice > max_choice - 3) && (scroll + max_choice < item_no)) { /* Scroll menu up */ do_scroll(menu, &scroll, 1); print_item(scroll+max_choice - 1, max_choice - 1, FALSE); } else choice = MIN(choice + 1, max_choice - 1); } else if (key == KEY_PPAGE) { scrollok(menu, TRUE); for (i = 0; (i < max_choice); i++) { if (scroll > 0) { do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else { if (choice > 0) choice--; } } } else if (key == KEY_NPAGE) { for (i = 0; (i < max_choice); i++) { if (scroll + max_choice < item_no) { do_scroll(menu, &scroll, 1); print_item(scroll+max_choice-1, max_choice - 1, FALSE); } else { if (choice + 1 < max_choice) choice++; } } } else choice = i; print_item(scroll + choice, choice, TRUE); print_arrows(dialog, item_no, scroll, box_y, box_x + item_x + 1, menu_height); wnoutrefresh(dialog); wrefresh(menu); continue; /* wait for another key press */ } switch (key) { case KEY_LEFT: case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 2 : (button > 2 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(menu); break; case ' ': case 's': case 'y': case 'n': case 'm': case '/': /* save scroll info */ if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { fprintf(f, "%d\n", scroll); fclose(f); } delwin(dialog); fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); switch (key) { case 's': return 3; case 'y': return 3; case 'n': return 4; case 'm': return 5; case ' ': return 6; case '/': return 7; } return 0; case 'h': case '?': button = 2; case '\n': delwin(dialog); if (button == 2) fprintf(stderr, "%s \"%s\"\n", items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1] + first_alpha(items [(scroll + choice) * 2 + 1], "")); else fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); remove("lxdialog.scrltmp"); return button; case 'e': case 'x': key = ESC; case ESC: break; } } delwin(dialog); remove("lxdialog.scrltmp"); return -1; /* ESC presgsed */ }
void draw_slot(void) { if (!boarding(ms, 0)) { mvwaddstr(slot_w, 0, 0, " "); mvwaddstr(slot_w, 1, 0, " "); } else mvwaddstr(slot_w, 1, 0, "OBP"); if (!boarding(ms, 1)) { mvwaddstr(slot_w, 2, 0, " "); mvwaddstr(slot_w, 3, 0, " "); } else mvwaddstr(slot_w, 3, 0, "DBP"); wmove(slot_w, SLOT_Y-4, 0); if (mf->RH) wprintw(slot_w, "%dRH", mf->RH); else waddstr(slot_w, " "); wmove(slot_w, SLOT_Y-3, 0); if (mf->RG) wprintw(slot_w, "%dRG", mf->RG); else waddstr(slot_w, " "); wmove(slot_w, SLOT_Y-2, 0); if (mf->RR) wprintw(slot_w, "%dRR", mf->RR); else waddstr(slot_w, " "); #define Y (SLOT_Y/2) wmove(slot_w, 7, 1); wprintw(slot_w,"%d", windspeed); mvwaddch(slot_w, Y, 0, ' '); mvwaddch(slot_w, Y, 2, ' '); mvwaddch(slot_w, Y-1, 0, ' '); mvwaddch(slot_w, Y-1, 1, ' '); mvwaddch(slot_w, Y-1, 2, ' '); mvwaddch(slot_w, Y+1, 0, ' '); mvwaddch(slot_w, Y+1, 1, ' '); mvwaddch(slot_w, Y+1, 2, ' '); wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]); switch (winddir) { case 1: case 5: waddch(slot_w, '|'); break; case 2: case 6: waddch(slot_w, '/'); break; case 3: case 7: waddch(slot_w, '-'); break; case 4: case 8: waddch(slot_w, '\\'); break; } mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+'); wrefresh(slot_w); }
void inputTest(WINDOW *win) { int w, h, bx, by, sw, sh, i, c, num = 0; char buffer[80]; WINDOW *subWin; static const char spinner[4] = "/-\\|"; int spinner_count = 0; wclear(win); getmaxyx(win, h, w); getbegyx(win, by, bx); sw = w / 3; sh = h / 3; if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL) return; #ifdef A_COLOR if (has_colors()) { init_pair(2, COLOR_WHITE, COLOR_RED); wbkgd(subWin, COLOR_PAIR(2) | A_BOLD); } else #endif wbkgd(subWin, A_BOLD); box(subWin, ACS_VLINE, ACS_HLINE); wrefresh(win); nocbreak(); wclear (win); mvwaddstr(win, 1, 1, "Press keys (or mouse buttons) to show their names"); mvwaddstr(win, 2, 1, "Press spacebar to finish"); wrefresh(win); keypad(win, TRUE); raw(); noecho(); wtimeout(win, 200); #ifdef PDCURSES mouse_set(ALL_MOUSE_EVENTS); PDC_save_key_modifiers(TRUE); PDC_return_key_modifiers(TRUE); #endif curs_set(0); /* turn cursor off */ while (1) { while (1) { c = wgetch(win); if (c == ERR) { spinner_count++; if (spinner_count == 4) spinner_count = 0; mvwaddch(win, 3, 3, spinner[spinner_count]); wrefresh(win); } else break; } #ifdef PDCURSES wmove(win, 4, 18); wclrtoeol(win); #endif mvwaddstr(win, 3, 5, "Key Pressed: "); wclrtoeol(win); if (c >= KEY_MIN) wprintw(win, "%s", keyname(c)); else if (isprint(c)) wprintw(win, "%c", c); else wprintw(win, "%s", unctrl(c)); #ifdef PDCURSES if (c == KEY_MOUSE) { int button = 0; request_mouse_pos(); if (BUTTON_CHANGED(1)) button = 1; else if (BUTTON_CHANGED(2)) button = 2; else if (BUTTON_CHANGED(3)) button = 3; if (button && (BUTTON_STATUS(button) & BUTTON_MODIFIER_MASK)) { waddstr(win, " Modifier(s):"); if (BUTTON_STATUS(button) & BUTTON_SHIFT) waddstr(win, " SHIFT"); if (BUTTON_STATUS(button) & BUTTON_CONTROL) waddstr(win, " CONTROL"); if (BUTTON_STATUS(button) & BUTTON_ALT) waddstr(win, " ALT"); } wmove(win, 4, 18); wclrtoeol(win); wprintw(win, "Button %d: ", button); if (MOUSE_MOVED) waddstr(win, "moved: "); else if (MOUSE_WHEEL_UP) waddstr(win, "wheel up: "); else if (MOUSE_WHEEL_DOWN) waddstr(win, "wheel dn: "); else if (MOUSE_WHEEL_LEFT) waddstr(win, "wheel lt: "); else if (MOUSE_WHEEL_RIGHT) waddstr(win, "wheel rt: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED) waddstr(win, "pressed: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_CLICKED) waddstr(win, "clicked: "); else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) waddstr(win, "double: "); else waddstr(win, "released: "); wprintw(win, "Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS); } else if (PDC_get_key_modifiers()) { waddstr(win, " Modifier(s):"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_SHIFT) waddstr(win, " SHIFT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_CONTROL) waddstr(win, " CONTROL"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_ALT) waddstr(win, " ALT"); if (PDC_get_key_modifiers() & PDC_KEY_MODIFIER_NUMLOCK) waddstr(win, " NUMLOCK"); } #endif wrefresh(win); if (c == ' ') break; } wtimeout(win, -1); /* turn off timeout() */ curs_set(1); /* turn cursor back on */ #ifdef PDCURSES mouse_set(0L); PDC_save_key_modifiers(FALSE); PDC_return_key_modifiers(FALSE); #endif wclear(win); mvwaddstr(win, 2, 1, "Press some keys for 5 seconds"); mvwaddstr(win, 1, 1, "Pressing ^C should do nothing"); wrefresh(win); werase(subWin); box(subWin, ACS_VLINE, ACS_HLINE); for (i = 0; i < 5; i++) { mvwprintw(subWin, 1, 1, "Time = %d", i); wrefresh(subWin); napms(1000); flushinp(); } delwin(subWin); werase(win); flash(); wrefresh(win); napms(500); flushinp(); mvwaddstr(win, 2, 1, "Press a key, followed by ENTER"); wmove(win, 9, 10); wrefresh(win); echo(); keypad(win, TRUE); raw(); wgetnstr(win, buffer, 3); flushinp(); wmove(win, 9, 10); wdelch(win); mvwaddstr(win, 4, 1, "The character should now have been deleted"); Continue(win); refresh(); wclear(win); echo(); buffer[0] = '\0'; mvwaddstr(win, 3, 2, "The window should have moved"); mvwaddstr(win, 4, 2, "This text should have appeared without you pressing a key"); mvwaddstr(win, 6, 2, "Enter a number then a string seperated by space"); mvwin(win, 2, 1); wrefresh(win); mvwscanw(win, 7, 6, "%d %s", &num, buffer); mvwprintw(win, 8, 6, "String: %s Number: %d", buffer, num); Continue(win); refresh(); wclear(win); echo(); mvwaddstr(win, 3, 2, "Enter a 5 character string: "); wgetnstr(win, buffer, 5); mvwprintw(win, 4, 2, "String: %s", buffer); Continue(win); }
static void update_status(WINDOW *win, STATUS * sp) { switch (sp->ch) { case ' ': /* next test-iteration */ if (has_colors()) { if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) { sp->c_msg = color_params(sp->c = 0, &(sp->pair)); if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) { sp->v_msg = video_params(sp->v = 0, &(sp->attr)); } } } else { if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) { sp->v_msg = video_params(sp->v = 0, &(sp->attr)); } } sp->count = 0; show_status(win, sp); break; case KEY_LEFT: case 'h': if (sp->x_val > 0) wmove(win, sp->y_val, --(sp->x_val)); break; case KEY_DOWN: case 'j': if (sp->y_val < sp->y_max) wmove(win, ++(sp->y_val), sp->x_val); break; case KEY_UP: case 'k': if (sp->y_val > 0) wmove(win, --(sp->y_val), sp->x_val); break; case KEY_RIGHT: case 'l': if (sp->x_val < sp->x_max) wmove(win, sp->y_val, ++(sp->x_val)); break; case 't': touchline(win, sp->y_val, 1); break; case '=': sp->count = 0; show_status(win, sp); break; case '-': sp->count = -(sp->count); show_status(win, sp); break; case '?': do_subwindow(win, sp, show_help); break; default: if (isdigit(sp->ch)) { sp->count = (sp->count * 10) + (sp->ch - '0'); show_status(win, sp); } else { beep(); } break; } }
static void blocklist_onDraw(ToxWindow *self, Tox *m, int y2, int x2) { wattron(self->window, A_BOLD); wprintw(self->window, " Blocked: "); wattroff(self->window, A_BOLD); wprintw(self->window, "%d\n\n", Blocked_Contacts.num_blocked); if ((y2 - FLIST_OFST) <= 0) return; int selected_num = 0; /* Determine which portion of friendlist to draw based on current position */ int page = Blocked_Contacts.num_selected / (y2 - FLIST_OFST); int start = (y2 - FLIST_OFST) * page; int end = y2 - FLIST_OFST + start; int i; for (i = start; i < Blocked_Contacts.num_blocked && i < end; ++i) { int f = Blocked_Contacts.index[i]; bool f_selected = false; if (i == Blocked_Contacts.num_selected) { wattron(self->window, A_BOLD); wprintw(self->window, " > "); wattroff(self->window, A_BOLD); selected_num = f; f_selected = true; } else { wprintw(self->window, " "); } wattron(self->window, COLOR_PAIR(RED)); wprintw(self->window, "x"); wattroff(self->window, COLOR_PAIR(RED)); if (f_selected) wattron(self->window, COLOR_PAIR(BLUE)); wattron(self->window, A_BOLD); wprintw(self->window, " %s\n", Blocked_Contacts.list[f].name); wattroff(self->window, A_BOLD); if (f_selected) wattroff(self->window, COLOR_PAIR(BLUE)); } wprintw(self->window, "\n"); self->x = x2; if (Blocked_Contacts.num_blocked) { wmove(self->window, y2 - 1, 1); wattron(self->window, A_BOLD); wprintw(self->window, "ID: "); wattroff(self->window, A_BOLD); int i; for (i = 0; i < TOX_CLIENT_ID_SIZE; ++i) wprintw(self->window, "%02X", Blocked_Contacts.list[selected_num].pub_key[i] & 0xff); } wrefresh(self->window); draw_del_popup(); if (self->help->active) help_onDraw(self); }
void quaff() { THING *obj, *tp, *mp; bool discardit = FALSE; bool show, trip; obj = get_item("quaff", POTION); /* * Make certain that it is somethings that we want to drink */ if (obj == NULL) return; if (obj->o_type != POTION) { if (!terse) msg("yuk! Why would you want to drink that?"); else msg("that's undrinkable"); return; } if (obj == cur_weapon) cur_weapon = NULL; /* * Calculate the effect it has on the poor guy. */ trip = on(player, ISHALU); discardit = (bool)(obj->o_count == 1); leave_pack(obj, FALSE, FALSE); switch (obj->o_which) { case P_CONFUSE: do_pot(P_CONFUSE, !trip); when P_POISON: pot_info[P_POISON].oi_know = TRUE; if (ISWEARING(R_SUSTSTR)) msg("you feel momentarily sick"); else { chg_str(-(rnd(3) + 1)); msg("you feel very sick now"); come_down(); } when P_HEALING: pot_info[P_HEALING].oi_know = TRUE; if ((pstats.s_hpt += roll(pstats.s_lvl, 4)) > max_hp) pstats.s_hpt = ++max_hp; sight(); msg("you begin to feel better"); when P_STRENGTH: pot_info[P_STRENGTH].oi_know = TRUE; chg_str(1); msg("you feel stronger, now. What bulging muscles!"); when P_MFIND: player.t_flags |= SEEMONST; fuse((void(*)())turn_see, TRUE, HUHDURATION, AFTER); if (!turn_see(FALSE)) msg("you have a %s feeling for a moment, then it passes", choose_str("normal", "strange")); when P_TFIND: /* * Potion of magic detection. Show the potions and scrolls */ show = FALSE; if (lvl_obj != NULL) { wclear(hw); for (tp = lvl_obj; tp != NULL; tp = next(tp)) { if (is_magic(tp)) { show = TRUE; wmove(hw, tp->o_pos.y, tp->o_pos.x); waddch(hw, MAGIC); pot_info[P_TFIND].oi_know = TRUE; } } for (mp = mlist; mp != NULL; mp = next(mp)) { for (tp = mp->t_pack; tp != NULL; tp = next(tp)) { if (is_magic(tp)) { show = TRUE; wmove(hw, mp->t_pos.y, mp->t_pos.x); waddch(hw, MAGIC); } } } } if (show) { pot_info[P_TFIND].oi_know = TRUE; show_win("You sense the presence of magic on this level.--More--"); } else msg("you have a %s feeling for a moment, then it passes", choose_str("normal", "strange")); when P_LSD: if (!trip) { if (on(player, SEEMONST)) turn_see(FALSE); start_daemon(visuals, 0, BEFORE); seenstairs = seen_stairs(); } do_pot(P_LSD, TRUE); when P_SEEINVIS: sprintf(prbuf, "this potion tastes like %s juice", fruit); show = on(player, CANSEE); do_pot(P_SEEINVIS, FALSE); if (!show) invis_on(); sight(); when P_RAISE: pot_info[P_RAISE].oi_know = TRUE; msg("you suddenly feel much more skillful"); raise_level(); when P_XHEAL: pot_info[P_XHEAL].oi_know = TRUE; if ((pstats.s_hpt += roll(pstats.s_lvl, 8)) > max_hp) { if (pstats.s_hpt > max_hp + pstats.s_lvl + 1) ++max_hp; pstats.s_hpt = ++max_hp; } sight(); come_down(); msg("you begin to feel much better"); when P_HASTE: pot_info[P_HASTE].oi_know = TRUE; after = FALSE; if (add_haste(TRUE)) msg("you feel yourself moving much faster"); when P_RESTORE: if (ISRING(LEFT, R_ADDSTR)) add_str(&pstats.s_str, -cur_ring[LEFT]->o_arm); if (ISRING(RIGHT, R_ADDSTR)) add_str(&pstats.s_str, -cur_ring[RIGHT]->o_arm); if (pstats.s_str < max_stats.s_str) pstats.s_str = max_stats.s_str; if (ISRING(LEFT, R_ADDSTR)) add_str(&pstats.s_str, cur_ring[LEFT]->o_arm); if (ISRING(RIGHT, R_ADDSTR)) add_str(&pstats.s_str, cur_ring[RIGHT]->o_arm); msg("hey, this tastes great. It make you feel warm all over"); when P_BLIND: do_pot(P_BLIND, TRUE); when P_LEVIT: do_pot(P_LEVIT, TRUE); #ifdef MASTER otherwise: msg("what an odd tasting potion!"); return; #endif } status(); /* * Throw the item away */ call_it(&pot_info[obj->o_which]); if (discardit) discard(obj); return; }
/* implement basic frame work to build a field input */ char * input_string (WINDOW * win, int pos_y, int pos_x, size_t max_width, const char *str, int enable_case, int *toggle_case) { char *s = xmalloc (max_width + 1), *tmp; size_t pos = 0, x = 0, quit = 1, c; /* window dimensions */ size_t size_x = 0, size_y = 0, i; getmaxyx (win, size_y, size_x); size_x -= 4; /* are we setting a default string */ if (str) { size_t len = MIN (max_width, strlen (str)); memcpy (s, str, len); s[len] = '\0'; x = pos = 0; /* is the default str length greater than input field? */ if (strlen (s) > size_x) { tmp = xstrdup (&s[0]); tmp[size_x] = '\0'; mvwprintw (win, pos_y, pos_x, "%s", tmp); free (tmp); } else mvwprintw (win, pos_y, pos_x, "%s", s); } else s[0] = '\0'; if (enable_case) draw_header (win, "[x] case sensitive", " %s", size_y - 2, 1, size_x - 2, 2, 0); wmove (win, pos_y, pos_x + x); wrefresh (win); curs_set (1); while (quit) { c = wgetch (stdscr); switch (c) { case 1: /* ^a */ case 262: /* HOME */ pos = x = 0; break; case 5: case 360: /* END of line */ if (strlen (s) > size_x) { x = size_x; pos = strlen (s) - size_x; } else { pos = 0; x = strlen (s); } break; case 7: /* ^g */ case 27: /* ESC */ pos = x = 0; if (str && *str == '\0') s[0] = '\0'; quit = 0; break; case 9: /* TAB */ if (!enable_case) break; *toggle_case = *toggle_case == 0 ? 1 : 0; if (*toggle_case) draw_header (win, "[ ] case sensitive", " %s", size_y - 2, 1, size_x - 2, 2, 0); else if (!*toggle_case) draw_header (win, "[x] case sensitive", " %s", size_y - 2, 1, size_x - 2, 2, 0); break; case 21: /* ^u */ s[0] = '\0'; pos = x = 0; break; case 8: /* xterm-256color */ case 127: case KEY_BACKSPACE: if (pos + x > 0) { memmove (&s[(pos + x) - 1], &s[pos + x], (max_width - (pos + x)) + 1); if (pos <= 0) x--; else pos--; } break; case KEY_LEFT: if (x > 0) x--; else if (pos > 0) pos--; break; case KEY_RIGHT: if ((x + pos) < strlen (s)) { if (x < size_x) x++; else pos++; } break; case 0x0a: case 0x0d: case KEY_ENTER: quit = 0; break; default: if (strlen (s) == max_width) break; if (!isprint (c)) break; if (strlen (s) == pos) { s[pos + x] = c; s[pos + x + 1] = '\0'; waddch (win, c); } else { memmove (&s[pos + x + 1], &s[pos + x], strlen (&s[pos + x]) + 1); s[pos + x] = c; } if ((x + pos) < max_width) { if (x < size_x) x++; else pos++; } } tmp = xstrdup (&s[pos > 0 ? pos : 0]); tmp[MIN (strlen (tmp), size_x)] = '\0'; for (i = strlen (tmp); i < size_x; i++) mvwprintw (win, pos_y, pos_x + i, "%s", " "); mvwprintw (win, pos_y, pos_x, "%s", tmp); free (tmp); wmove (win, pos_y, pos_x + x); wrefresh (win); } curs_set (0); return s; }
void ui_refresh_display (unsigned int x, unsigned int y, char c) { wmove (display_win, y+1, x+1); wprintw (display_win, "%c", c); wrefresh (display_win); }
void ui_update_ball_tracker (unsigned int ballno, const char *location) { wmove (ball_tracker_win, ballno+1, 1); wprintw (ball_tracker_win, "%d: %-14.14s", ballno, location); wrefresh (ball_tracker_win); }
void ui_write_sound_command (unsigned int x) { wmove (sound_win, 1, 1); wprintw (sound_win, "%04X", x); wrefresh (sound_win); }
void ui_write_sound_reset (void) { wmove (sound_win, 1, 1); wprintw (sound_win, " "); wrefresh (sound_win); }
/* MAIN Envoyer et recevoir des donnes Gere les fenetres du GUI */ int main (int argc, char* argv[]) { if ( argc < 2 ) { printf ("Usage: %s PORT\n", argv[0]); exit (EXIT_FAILURE); } initscr(); // Start curses mode cbreak(); // Line buffering disabled, Pass on everty thing to me //my_win = create_newwin(height, width, starty, startx); f_haut = definirFenetre( f_haut_hauteur, COLS, 0, 0 ); f_bas = definirFenetre( f_bas_hauteur, COLS, (LINES - f_bas_hauteur - marge_bas), 0 ); f_info = definirFenetre( f_info_hauteur, COLS, (LINES - donnerHauteur(f_bas) - f_info_hauteur - marge_bas), 0 ); f_cmd = definirFenetre( f_cmd_hauteur, COLS, (LINES - donnerHauteur(f_bas) - donnerHauteur(f_info) - marge_bas - f_cmd_hauteur), 0); f_chat = definirFenetre( (LINES - donnerHauteur(f_haut) - donnerHauteur(f_cmd) - donnerHauteur(f_info) - donnerHauteur(f_bas) - marge_bas), COLS, donnerHauteur(f_haut), 0 ); refresh(); w_haut = create_newwin_with_border( f_haut ); w_bas = create_newwin_no_border( f_bas ); w_info = create_newwin_with_border( f_info ); w_cmd = create_newwin_with_border( f_cmd ); w_chat = create_newwin_no_border( f_chat ); scrollok( w_chat, 1 ); wsetscrreg( w_chat, donnerStarty(f_chat), donnerHauteur(f_chat) ); wtimeout(w_bas, 500); mvwprintw(w_haut, 1, 1, "CHAT CLIENT"); mvwprintw(w_cmd, 1, 1, ""); mvwprintw(w_info, 1, 1, "/nom usager\t/mp usager msg\t/creer groupe type\t/info groupe\t\t/accept usager groupe"); mvwprintw(w_info, 2, 1, "\t\t/mg groupe msg\t/joindre groupe\t\t/liste usagers\t\t/refuser usager groupe"); mvwprintw(w_info, 3, 1, "/quitter\t\t\t/byebye groupe\t\t/liste groupes\t\t/stats groupe"); wmove( w_bas, 0, 0 ); wrefresh(w_haut); wrefresh(w_info); wrefresh(w_bas); wrefresh(w_cmd); struct sockaddr_in serveur; struct hostent* hp; socket_d = socket (AF_INET, SOCK_STREAM, 0); if (socket_d < 0) { endwin(); printf("Erreur lors de la création de la socket !\n"); return 1; } setnonblocking (socket_d); hp = gethostbyname("localhost"); if (hp==0) { endwin(); close (socket_d); printf("Hôte inconnu!\n"); return 2; } serveur.sin_family = AF_INET; serveur.sin_port = htons(atoi(argv[1])); bcopy((char *)hp->h_addr, (char *)&serveur.sin_addr, hp->h_length); if ( connect(socket_d,(struct sockaddr *)&serveur,sizeof(struct sockaddr_in)) < 0 ) { endwin(); close (socket_d); printf("Erreur lors de la création d'une nouvelle connexion !\n"); return 3; } nom_usager_defini = 0; input = chaineCreerVide( COLS ); while ( 1 ) { key_handler(); if ( ! recv_handler() ) break; } endwin (); close (socket_d); return 0; }
/* Traitement du standard input */ void key_handler () { int ch = wgetch(w_bas); int longueur = chaineLongueur(input); if ( ch != '\n' && ch != ERR && ch!= 127 ) { // AJOUTER CHAR chaineAjouter( input, ch ); if ( longueur > COLS ) { mvwprintw(w_bas, 0, 0, "%s", &chaineValeur(input)[longueur-COLS] ); } } else if ( ch == 127 ) { // BACKSPACE if ( chaineLongueur(input) > 0 ) { chaineEnlever(input); delwin(w_bas); w_bas = create_newwin_no_border( f_bas ); if ( longueur > COLS ) { mvwprintw(w_bas, 0, 0, "%s", &chaineValeur(input)[longueur-COLS] ); } else { mvwprintw( w_bas, 0, 0, "%s", chaineValeur(input) ); } } else { delwin(w_bas); w_bas = create_newwin_no_border( f_bas ); wmove( w_bas, 0, 0 ); } } else if ( ch == '\n' ) { // ENTER delwin(w_cmd); w_cmd = create_newwin_with_border( f_cmd ); mvwprintw(w_cmd, 1, 1, "%s", chaineValeur(input) ); delwin(w_bas); w_bas = create_newwin_no_border( f_bas ); wmove( w_bas, 0, 0 ); char buffer[BUF_SIZE]; sprintf ( buffer, "%s", chaineValeur(input) ); decomposer_commande (buffer); if ( nom_usager_defini == 1 && !strcmp("/nom", cmd.chaine[0]) ) { wprintw (w_chat, "Erreur! Vous ne pouvez pas changer de nom!\n"); } else if ( nom_usager_defini == 0 && strcmp("/nom", cmd.chaine[0]) ) { wprintw (w_chat, "Erreur! Vous devez definir un nom d'usager tout d'abord!\n"); } else { int n = send (socket_d, buffer, strlen(buffer)+1, 0); if ( n < 0 ) wprintw(w_chat, "Erreur lors de l'envoi\n"); } chaineSupprime( input ); input = chaineCreerVide( COLS ); } wmove( w_bas, 0, chaineLongueur(input) ); wrefresh(w_chat); wrefresh(w_cmd); wrefresh(w_bas); }
/* * Display text from a file in a dialog box. */ int dialog_textbox(const char *title, const char *tbuf, int initial_height, int initial_width) { int i, x, y, cur_x, cur_y, key = 0; int height, width, boxh, boxw; int passed_end; WINDOW *dialog, *box; begin_reached = 1; end_reached = 0; page_length = 0; hscroll = 0; buf = tbuf; page = buf; /* page is pointer to start of page to be displayed */ do_resize: getmaxyx(stdscr, height, width); if (height < 8 || width < 8) return -ERRDISPLAYTOOSMALL; if (initial_height != 0) height = initial_height; else if (height > 4) height -= 4; else height = 0; if (initial_width != 0) width = initial_width; else if (width > 5) width -= 5; else width = 0; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); /* Create window for box region, used for scrolling text */ boxh = height - 4; boxw = width - 2; box = subwin(dialog, boxh, boxw, y + 1, x + 1); wattrset(box, dlg.dialog.atr); wbkgdset(box, dlg.dialog.atr & A_COLOR); keypad(box, TRUE); /* register the new window, along with its borders */ draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); wbkgdset(dialog, dlg.dialog.atr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE); wnoutrefresh(dialog); getyx(dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear(box, boxh, boxw, dlg.dialog.atr); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); while ((key != KEY_ESC) && (key != '\n')) { key = wgetch(dialog); switch (key) { case 'E': /* Exit */ case 'e': case 'X': case 'x': delwin(box); delwin(dialog); return 0; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; page = buf; refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); } break; case 'G': /* Last page */ case KEY_END: end_reached = 1; /* point to last char in buf */ page = buf + strlen(buf); back_lines(boxh); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'K': /* Previous line */ case 'k': case KEY_UP: if (!begin_reached) { back_lines(page_length + 1); /* We don't call print_page() here but use * scrolling to ensure faster screen update. * However, 'end_reached' and 'page_length' * should still be updated, and 'page' should * point to start of next page. This is done * by calling get_line() in the following * 'for' loop. */ scrollok(box, TRUE); wscrl(box, -1); /* Scroll box region down one line */ scrollok(box, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < boxh; i++) { if (!i) { /* print first line of page */ print_line(box, 0, boxw); wnoutrefresh(box); } else /* Called to update 'end_reached' and 'page' */ get_line(); if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (begin_reached) break; back_lines(page_length + boxh); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'J': /* Next line */ case 'j': case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok(box, TRUE); scroll(box); /* Scroll box region up one line */ scrollok(box, FALSE); print_line(box, boxh - 1, boxw); wnoutrefresh(box); print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } break; case KEY_NPAGE: /* Next page */ case ' ': if (end_reached) break; begin_reached = 0; refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ case 'h': case KEY_LEFT: if (hscroll <= 0) break; if (key == '0') hscroll = 0; else hscroll--; /* Reprint current page to scroll horizontally */ back_lines(page_length); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case 'L': /* Scroll right */ case 'l': case KEY_RIGHT: if (hscroll >= MAX_LEN) break; hscroll++; /* Reprint current page to scroll horizontally */ back_lines(page_length); refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: back_lines(height); delwin(box); delwin(dialog); on_key_resize(); goto do_resize; } } delwin(box); delwin(dialog); return key; /* ESC pressed */ }
int mvwaddchstr(WINDOW *win, int y, int x, chtype *ch) { return (wmove(win, y, x) == ERR ? ERR : waddchstr(win, ch)); }
/* * Write the soft labels to the soft-key window. */ static void slk_intern_refresh(SCREEN *sp) { int i; int fmt; SLK *slk; int numlab; if (sp == 0) return; slk = sp->_slk; fmt = sp->slk_format; numlab = NumLabels; if (slk->hidden) return; for (i = 0; i < slk->labcnt; i++) { if (slk->dirty || slk->ent[i].dirty) { if (slk->ent[i].visible) { if (numlab > 0 && SLK_STDFMT(fmt)) { #ifdef USE_TERM_DRIVER CallDriver_2(sp, hwlabel, i + 1, slk->ent[i].form_text); #else if (i < num_labels) { TPUTS_TRACE("plab_norm"); putp(TPARM_2(plab_norm, i + 1, slk->ent[i].form_text)); } #endif } else { if (fmt == 4) slk_paint_info(slk->win); wmove(slk->win, SLK_LINES(fmt) - 1, slk->ent[i].ent_x); if (sp->_slk) { (void) wattrset(slk->win, AttrOf(sp->_slk->attr)); } waddstr(slk->win, slk->ent[i].form_text); /* if we simulate SLK's, it's looking much more natural to use the current ATTRIBUTE also for the label window */ (void) wattrset(slk->win, WINDOW_ATTRS(StdScreen(sp))); } } slk->ent[i].dirty = FALSE; } } slk->dirty = FALSE; if (numlab > 0) { #ifdef USE_TERM_DRIVER CallDriver_1(sp, hwlabelOnOff, slk->hidden ? FALSE : TRUE); #else if (slk->hidden) { TPUTS_TRACE("label_off"); putp(label_off); } else { TPUTS_TRACE("label_on"); putp(label_on); } #endif } }
void tx_getinput(struct FIELDLIST *list, struct FIELD *field, int *exitkey) { int ch; int y, x; int endloop = 0; wattrset(list->fieldwin, list->fieldattr); mvwprintw(list->fieldwin, field->ypos, field->xpos, "%s", field->buf); update_panels(); doupdate(); do { ch = wgetch(list->fieldwin); switch (ch) { case KEY_BACKSPACE: case 7: case 8: case KEY_DC: case KEY_LEFT: case 127: if (field->tlen > 0) { getyx(list->fieldwin, y, x); x--; mvwprintw(list->fieldwin, y, x, " "); wmove(list->fieldwin, y, x); field->tlen--; field->buf[field->tlen] = '\0'; } break; case 9: case 27: case 24: case 13: case 10: case KEY_UP: case KEY_DOWN: endloop = 1; *exitkey = ch; break; case 12: tx_refresh_screen(); break; default: if ((field->tlen < field->len) && ((ch >= 32) && (ch <= 127))) { wprintw(list->fieldwin, "%c", ch); if (ch == ' ') { getyx(list->fieldwin, y, x); wmove(list->fieldwin, y, x); } field->buf[field->tlen + 1] = '\0'; field->buf[field->tlen] = ch; field->tlen++; } break; } doupdate(); } while (!endloop); }
static void ui_window_draw(UiWin *w) { UiCursesWin *win = (UiCursesWin*)w; if (!ui_window_draw_sidebar(win)) return; debug("ui-win-draw[%s]\n", win->file->name ? win->file->name : "noname"); wbkgd(win->win, style_to_attr(&win->styles[UI_STYLE_DEFAULT])); wmove(win->win, 0, 0); int width = view_width_get(win->view); CellStyle *prev_style = NULL; size_t cursor_lineno = -1; if (win->options & UI_OPTION_CURSOR_LINE && win->ui->selwin == win) { Filerange selection = view_selection_get(win->view); if (!view_cursors_multiple(win->view) && !text_range_valid(&selection)) { const Line *line = view_line_get(win->view); cursor_lineno = line->lineno; } } short selection_bg = win->styles[UI_STYLE_SELECTION].bg; short cursor_line_bg = win->styles[UI_STYLE_CURSOR_LINE].bg; bool multiple_cursors = view_cursors_multiple(win->view); attr_t attr = A_NORMAL; for (const Line *l = view_lines_get(win->view); l; l = l->next) { bool cursor_line = l->lineno == cursor_lineno; for (int x = 0; x < width; x++) { enum UiStyle style_id = l->cells[x].style; if (style_id == 0) style_id = UI_STYLE_DEFAULT; CellStyle *style = &win->styles[style_id]; if (l->cells[x].cursor && win->ui->selwin == win) { if (multiple_cursors && l->cells[x].cursor_primary) attr = style_to_attr(&win->styles[UI_STYLE_CURSOR_PRIMARY]); else attr = style_to_attr(&win->styles[UI_STYLE_CURSOR]); prev_style = NULL; } else if (l->cells[x].selected) { if (style->fg == selection_bg) attr |= A_REVERSE; else attr = style->attr | COLOR_PAIR(color_pair_get(style->fg, selection_bg)); prev_style = NULL; } else if (cursor_line) { attr = style->attr | COLOR_PAIR(color_pair_get(style->fg, cursor_line_bg)); prev_style = NULL; } else if (style != prev_style) { attr = style_to_attr(style); prev_style = style; } wattrset(win->win, attr); waddstr(win->win, l->cells[x].data); } /* try to fixup display issues, in theory we should always output a full line */ int x, y; getyx(win->win, y, x); (void)y; wattrset(win->win, A_NORMAL); for (; 0 < x && x < width; x++) waddstr(win->win, " "); } wclrtobot(win->win); }
//Edits the current file void MenuEdit(list *FileBuffer, WINDOW *my_menu_win){ //Printing the existing file in the buffer to the window PrintBuffer(FileBuffer, my_menu_win); int x = 0, y = 2, c, choice = 0; int ymax = 2; //Creating temporary buffers char str[100][MAXCHAR], string[MAXCHAR]; int i = 0, j = 0; char ch; int ln = 2; node *p; //Copying the contents of the buffer into the 2D temporary buffer p = FileBuffer->head; while(p){ strcpy(&str[ln][0], p->string); p = p->next; ln++; } //If the buffer was non-empty, the contents of the temp buffer will be rewritten FreeBuffer(FileBuffer); InitialiseBuffer(FileBuffer); ymax = ln; y = ymax; x = 0; //Taking input from the user while((c = wgetch(my_menu_win)) != KEY_F(6) ||(c = wgetch(my_menu_win)) != KEY_F(3) ){ switch(c){ case KEY_UP: if (y > 2){ y--; wmove(my_menu_win, y, x); ln--; } break; case KEY_DOWN: y++; if (y > ymax) ymax = y; wmove(my_menu_win, y, x); ln++; break; case KEY_LEFT: if (x > 0){ x--; wmove(my_menu_win, y, x); i--; } break; case KEY_RIGHT: if (x < MAXCHAR){ x++; wmove(my_menu_win, y, x); i++; } break; case KEY_BACKSPACE: case 8: if (x > 0){ x--; wmove(my_menu_win, y, x); i--; } mvwprintw(my_menu_win, y, x, " "); str[y][x] = ' '; break; case 10: case 13: str[y][x] = '\n'; y++; ln++; if (y > ymax) ymax = y; x = 0; wmove(my_menu_win, y, x); break; //Escape case 27: choice = 1; break; default: str[y][x] = c; //Printing the character read to the screen mvwprintw(my_menu_win, y, x, "%c", c); x++; wmove(my_menu_win, y, x); break; } //If the user has pressed escape if (choice) break; } //Copying from temp buffer to permanent buffer for (i = 2; i < ymax ; i++){ //for each character that was read for (j = 0; str[i][j] != '\n'; j++){ string[j] = str[i][j]; } string[j] = '\0'; //Reinserting the strings from the temp buffer to the file buffer AppendtoBuffer(FileBuffer, string); } }
void BIOSSetCursor( unsigned char page, unsigned char row, unsigned char col ) { wmove( CursesWindow, row, col ); refresh(); }
/* render config log date/format dialog */ int verify_format (GLog * logger, GSpinner * spinner) { GMenu *menu; WINDOW *win; char *cstm_log, *cstm_date; int c, quit = 1; int invalid = 1; int y, x, h = CONF_WIN_H, w = CONF_WIN_W; int w2 = w - 2; size_t i, n, sel; /* conf dialog menu options */ const char *choices[] = { "NCSA Combined Log Format", "NCSA Combined Log Format with Virtual Host", "Common Log Format (CLF)", "Common Log Format (CLF) with Virtual Host", "W3C", "CloudFront (Download Distribution)" }; n = ARRAY_SIZE (choices); getmaxyx (stdscr, y, x); win = newwin (h, w, (y - h) / 2, (x - w) / 2); keypad (win, TRUE); wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); /* create a new instance of GMenu and make it selectable */ menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X); menu->size = n; menu->selectable = 1; /* add items to GMenu */ menu->items = (GItem *) xcalloc (n, sizeof (GItem)); for (i = 0; i < n; ++i) { menu->items[i].name = alloc_string (choices[i]); sel = get_selected_format_idx (); menu->items[i].checked = sel == i ? 1 : 0; } post_gmenu (menu); draw_header (win, "Log Format Configuration", " %s", 1, 1, w2, 1, 0); mvwprintw (win, 2, 2, "[SPACE] to toggle - [ENTER] to proceed"); /* set log format from goaccessrc if available */ draw_header (win, "Log Format - [c] to add/edit format", " %s", 11, 1, w2, 1, 0); if (conf.log_format) { log_format = escape_str (conf.log_format); mvwprintw (win, 12, 2, "%.*s", CONF_MENU_W, log_format); if (conf.log_format) free (conf.log_format); } /* set date format from goaccessrc if available */ draw_header (win, "Date Format - [d] to add/edit format", " %s", 14, 1, w2, 1, 0); if (conf.date_format) { date_format = escape_str (conf.date_format); mvwprintw (win, 15, 2, "%.*s", CONF_MENU_W, date_format); if (conf.date_format) free (conf.date_format); } wrefresh (win); while (quit) { c = wgetch (stdscr); switch (c) { case KEY_DOWN: gmenu_driver (menu, REQ_DOWN); draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); break; case KEY_UP: gmenu_driver (menu, REQ_UP); draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); break; case 32: /* space */ gmenu_driver (menu, REQ_SEL); if (date_format) free (date_format); if (log_format) free (log_format); for (i = 0; i < n; ++i) { if (menu->items[i].checked != 1) continue; date_format = get_selected_date_str (i); log_format = get_selected_format_str (i); draw_header (win, date_format, " %s", 15, 1, CONF_MENU_W, 0, 0); draw_header (win, log_format, " %s", 12, 1, CONF_MENU_W, 0, 0); break; } break; case 99: /* c */ /* clear top status bar */ draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); wmove (win, 12, 2); /* get input string */ cstm_log = input_string (win, 12, 2, 70, log_format, 0, 0); if (cstm_log != NULL && *cstm_log != '\0') { if (log_format) free (log_format); log_format = alloc_string (cstm_log); free (cstm_log); } /* did not set an input string */ else { if (cstm_log) free (cstm_log); if (log_format) { free (log_format); log_format = NULL; } } break; case 100: /* d */ /* clear top status bar */ draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0, 0); wmove (win, 15, 0); /* get input string */ cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0); if (cstm_date != NULL && *cstm_date != '\0') { if (date_format) free (date_format); date_format = alloc_string (cstm_date); free (cstm_date); } /* did not set an input string */ else { if (cstm_date) free (cstm_date); if (date_format) { free (date_format); date_format = NULL; } } break; case 274: /* F10 */ case 0x0a: case 0x0d: case KEY_ENTER: /* display status bar error messages */ if (date_format == NULL) draw_header (win, "Select a date format.", "%s", 3, 2, CONF_MENU_W, WHITE_RED, 0); if (log_format == NULL) draw_header (win, "Select a log format.", "%s", 3, 2, CONF_MENU_W, WHITE_RED, 0); if (date_format && log_format) { conf.date_format = unescape_str (date_format); conf.log_format = unescape_str (log_format); /* test log against selected settings */ if (test_format (logger)) { invalid = 1; draw_header (win, "No valid hits.", "%s", 3, 2, CONF_MENU_W, WHITE_RED, 0); free (conf.log_format); free (conf.date_format); } /* valid data, reset logger & start parsing */ else { reset_struct (logger); /* start spinner thread */ spinner->win = win; spinner->y = 3; spinner->x = 2; spinner->spin_x = CONF_MENU_W; spinner->w = CONF_MENU_W; spinner->color = BLACK_CYAN; ui_spinner_create (spinner); invalid = 0; quit = 0; } } break; case KEY_RESIZE: case 'q': quit = 0; break; } pthread_mutex_lock (&spinner->mutex); wrefresh (win); pthread_mutex_unlock (&spinner->mutex); } /* clean stuff up */ for (i = 0; i < n; ++i) free (menu->items[i].name); free (menu->items); free (menu); return invalid ? 1 : 0; }
unsigned int menu_choose_blocksize(unsigned int blocksize, const unsigned int sector_size, uint64_t *offset) { int command; unsigned int menu=0; const char *optionsBlocksize="BS51248736"; static const struct MenuItem menuBlocksize[]= { {'B',"1",""}, {'S',"256",""}, {'5',"512",""}, {'1',"1024",""}, {'2',"2048",""}, {'4',"4096",""}, {'8',"8192",""}, {'7',"16384",""}, {'3',"32768",""}, {'6',"65536",""}, {0,NULL,NULL} }; switch(sector_size) { case 256: optionsBlocksize+=1; break; case 512: optionsBlocksize+=2; break; case 1024: optionsBlocksize+=3; break; case 2048: optionsBlocksize+=4; break; case 4096: optionsBlocksize+=5; break; case 8192: optionsBlocksize+=6; break; case 16384: optionsBlocksize+=7;break; case 32768: optionsBlocksize+=8; break; case 65536: optionsBlocksize+=9; break; } switch(blocksize) { case 1: menu=0; break; case 256: menu=1; break; case 512: menu=2; break; case 1024: menu=3; break; case 2048: menu=4; break; case 4096: menu=5; break; case 8192: menu=6; break; case 16384: menu=7; break; case 32768: menu=8; break; case 65536: menu=9; break; } aff_copy(stdscr); wmove(stdscr,INTER_PARTITION_Y-1,0); wprintw(stdscr,"Please select the block size, press Enter when done."); command = wmenuSelect_ext(stdscr, 23, INTER_PARTITION_Y, INTER_PARTITION_X, menuBlocksize, 7, optionsBlocksize, MENU_VERT| MENU_BUTTON|MENU_VERT_WARN, &menu,NULL); switch(command) { case 'B': blocksize=1; break; case 'S': blocksize=256; break; case '5': blocksize=512; break; case '1': blocksize=1024; break; case '2': blocksize=2048; break; case '4': blocksize=4096; break; case '8': blocksize=8192; break; case '7': blocksize=16384; break; case '3': blocksize=32768; break; case '6': blocksize=65536; break; } *offset=*offset % blocksize; if(*offset%sector_size!=0) *offset=0; if(sector_size < blocksize) { unsigned int quit=0; aff_copy(stdscr); wmove(stdscr,INTER_PARTITION_Y-2,0); wprintw(stdscr,"Please select the offset (0 - %u). Press Up/Down to increase/decrease it,",blocksize-sector_size); wmove(stdscr,INTER_PARTITION_Y-1,0); wprintw(stdscr,"Enter when done."); do { wmove(stdscr,INTER_PARTITION_Y,0); wclrtoeol(stdscr); wprintw(stdscr,"Offset %u",(unsigned int)(*offset)); switch(wgetch(stdscr)) { case KEY_ENTER: #ifdef PADENTER case PADENTER: #endif case '\n': case '\r': quit=1; break; case KEY_PPAGE: case KEY_UP: case KEY_RIGHT: case '+': if(*offset + sector_size < blocksize) *offset+=sector_size; break; case KEY_NPAGE: case KEY_DOWN: case KEY_LEFT: case '-': if(*offset >= sector_size) *offset-=sector_size; break; } } while(quit==0); } return blocksize; }
static void test_inserts(int level) { static bool first = TRUE; int ch; int limit; int row = 1; int col; int row2, col2; int length; wchar_t buffer[BUFSIZ]; WINDOW *look = 0; WINDOW *work = 0; WINDOW *show = 0; int margin = (2 * MY_TABSIZE) - 1; Options option = ((m_opt ? oMove : oDefault) | ((w_opt || (level > 0)) ? oWindow : oDefault)); if (first) { static char cmd[80]; setlocale(LC_ALL, ""); putenv(strcpy(cmd, "TABSIZE=8")); initscr(); (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ keypad(stdscr, TRUE); } limit = LINES - 5; if (level > 0) { look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1); work = newwin(limit - 2, COLS - (2 * level), 1, level); show = newwin(4, COLS, limit + 1, 0); box(look, 0, 0); wnoutrefresh(look); limit -= 2; } else { work = stdscr; show = derwin(stdscr, 4, COLS, limit + 1, 0); } keypad(work, TRUE); for (col = margin + 1; col < COLS; col += MY_TABSIZE) MvWVLine(work, row, col, '.', limit - 2); MvWVLine(work, row, margin, ACS_VLINE, limit - 2); MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2); limit /= 2; MvWAddStr(work, 1, 2, "String"); MvWAddStr(work, limit + 1, 2, "Chars"); wnoutrefresh(work); buffer[length = 0] = '\0'; legend(show, level, option, buffer, length); wnoutrefresh(show); doupdate(); /* * Show the characters inserted in color, to distinguish from those that * are shifted. */ if (has_colors()) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgdset(work, COLOR_PAIR(1) | ' '); } while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) { wmove(work, row, margin + 1); switch (ch) { case key_RECUR: test_inserts(level + 1); touchwin(look); touchwin(work); touchwin(show); wnoutrefresh(look); wnoutrefresh(work); wnoutrefresh(show); doupdate(); break; case key_NEWLINE: if (row < limit) { ++row; /* put the whole string in, all at once */ col2 = margin + 1; switch (option) { case oDefault: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); if (move(row, col2) != ERR) { InsNStr(buffer + col, LEN(col)); } } } else { if (move(row, col2) != ERR) { InsStr(buffer); } } break; case oMove: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); MvInsNStr(row, col2, buffer + col, LEN(col)); } } else { MvInsStr(row, col2, buffer); } break; case oWindow: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); if (wmove(work, row, col2) != ERR) { WInsNStr(work, buffer + col, LEN(col)); } } } else { if (wmove(work, row, col2) != ERR) { WInsStr(work, buffer); } } break; case oMoveWindow: if (n_opt > 1) { for (col = 0; col < length; col += n_opt) { col2 = ColOf(buffer, col, margin); MvWInsNStr(work, row, col2, buffer + col, LEN(col)); } } else { MvWInsStr(work, row, col2, buffer); } break; } /* do the corresponding single-character insertion */ row2 = limit + row; for (col = 0; col < length; ++col) { col2 = ColOf(buffer, col, margin); switch (option) { case oDefault: if (move(row2, col2) != ERR) { InsCh((chtype) buffer[col]); } break; case oMove: MvInsCh(row2, col2, (chtype) buffer[col]); break; case oWindow: if (wmove(work, row2, col2) != ERR) { WInsCh(work, (chtype) buffer[col]); } break; case oMoveWindow: MvWInsCh(work, row2, col2, (chtype) buffer[col]); break; } } } else { beep(); } break; default: buffer[length++] = ch; buffer[length] = '\0'; /* put the string in, one character at a time */ col = ColOf(buffer, length - 1, margin); switch (option) { case oDefault: if (move(row, col) != ERR) { InsStr(buffer + length - 1); } break; case oMove: MvInsStr(row, col, buffer + length - 1); break; case oWindow: if (wmove(work, row, col) != ERR) { WInsStr(work, buffer + length - 1); } break; case oMoveWindow: MvWInsStr(work, row, col, buffer + length - 1); break; } /* do the corresponding single-character insertion */ switch (option) { case oDefault: if (move(limit + row, col) != ERR) { InsCh((chtype) ch); } break; case oMove: MvInsCh(limit + row, col, (chtype) ch); break; case oWindow: if (wmove(work, limit + row, col) != ERR) { WInsCh(work, (chtype) ch); } break; case oMoveWindow: MvWInsCh(work, limit + row, col, (chtype) ch); break; } wnoutrefresh(work); legend(show, level, option, buffer, length); wnoutrefresh(show); doupdate(); break; } } if (level > 0) { delwin(show); delwin(work); delwin(look); } }
static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const int verbose, unsigned int *sectors_per_cluster, uint64_t *offset_org, alloc_data_t *list_search_space) { uint64_t offset=0; uint64_t next_offset=0; uint64_t diff_offset=0; time_t previous_time=0; unsigned int nbr_subdir=0; sector_cluster_t sector_cluster[10]; alloc_data_t *current_search_space; unsigned char *buffer_start=(unsigned char *)MALLOC(READ_SIZE); unsigned char *buffer=buffer_start; assert(disk->sector_size!=0); current_search_space=td_list_entry(list_search_space->list.next, alloc_data_t, list); if(current_search_space!=list_search_space) offset=current_search_space->start; if(verbose>0) info_list_search_space(list_search_space, current_search_space, disk->sector_size, 0, verbose); #ifdef HAVE_NCURSES wmove(stdscr,22,0); wattrset(stdscr, A_REVERSE); waddstr(stdscr," Stop "); wattroff(stdscr, A_REVERSE); #endif disk->pread(disk, buffer_start, READ_SIZE, offset); while(current_search_space!=list_search_space && nbr_subdir<10) { const uint64_t old_offset=offset; if(buffer[0]=='.' && is_fat_directory(buffer)) { const unsigned long int cluster=fat_get_cluster_from_entry((const struct msdos_dir_entry *)buffer); log_info("sector %lu, cluster %lu\n", (unsigned long)(offset/disk->sector_size), cluster); sector_cluster[nbr_subdir].cluster=cluster; sector_cluster[nbr_subdir].sector=offset/disk->sector_size; log_flush(); nbr_subdir++; } get_next_sector(list_search_space, ¤t_search_space, &offset, 512); buffer+=512; if( old_offset+512!=offset || buffer+512>buffer_start+READ_SIZE) { buffer=buffer_start; #ifdef HAVE_NCURSES if(offset > next_offset) { const time_t current_time=time(NULL); if(current_time==previous_time) diff_offset<<=1; else diff_offset>>=1; if(diff_offset < disk->sector_size) diff_offset=disk->sector_size; next_offset=offset+diff_offset; previous_time=current_time; wmove(stdscr,9,0); wclrtoeol(stdscr); wprintw(stdscr,"Search subdirectory %10lu/%lu %u",(unsigned long)(offset/disk->sector_size),(unsigned long)(partition->part_size/disk->sector_size),nbr_subdir); wrefresh(stdscr); } #endif if(verbose>1) { log_verbose("Reading sector %10llu/%llu\n", (unsigned long long)((offset-partition->part_offset)/disk->sector_size), (unsigned long long)((partition->part_size-1)/disk->sector_size)); } if(disk->pread(disk, buffer_start, READ_SIZE, offset) != READ_SIZE) { #ifdef HAVE_NCURSES wmove(stdscr,11,0); wclrtoeol(stdscr); wprintw(stdscr,"Error reading sector %10lu\n", (unsigned long)((offset - partition->part_offset) / disk->sector_size)); #endif } } } /* end while(current_search_space!=list_search_space) */
static void friendlist_onDraw(ToxWindow *self, Tox *m) { curs_set(0); werase(self->window); int x2, y2; getmaxyx(self->window, y2, x2); bool fix_statuses = x2 != self->x; /* true if window max x value has changed */ wattron(self->window, COLOR_PAIR(CYAN)); wprintw(self->window, " Press the"); wattron(self->window, A_BOLD); wprintw(self->window, " H "); wattroff(self->window, A_BOLD); wprintw(self->window, "key for help\n\n"); wattroff(self->window, COLOR_PAIR(CYAN)); if (blocklist_view == 1) { blocklist_onDraw(self, m, y2, x2); return; } uint64_t cur_time = get_unix_time(); struct tm cur_loc_tm = *localtime((const time_t *) &cur_time); pthread_mutex_lock(&Winthread.lock); int nf = tox_get_num_online_friends(m); pthread_mutex_unlock(&Winthread.lock); wattron(self->window, A_BOLD); wprintw(self->window, " Online: "); wattroff(self->window, A_BOLD); wprintw(self->window, "%d/%d \n\n", nf, num_friends); if ((y2 - FLIST_OFST) <= 0) return; int selected_num = 0; /* Determine which portion of friendlist to draw based on current position */ int page = num_selected / (y2 - FLIST_OFST); int start = (y2 - FLIST_OFST) * page; int end = y2 - FLIST_OFST + start; int i; for (i = start; i < num_friends && i < end; ++i) { int f = friendlist_index[i]; bool f_selected = false; if (friends[f].active) { if (i == num_selected) { wattron(self->window, A_BOLD); wprintw(self->window, " > "); wattroff(self->window, A_BOLD); selected_num = f; f_selected = true; } else { wprintw(self->window, " "); } if (friends[f].online) { uint8_t status = friends[f].status; int colour = WHITE; switch (status) { case TOX_USERSTATUS_NONE: colour = GREEN; break; case TOX_USERSTATUS_AWAY: colour = YELLOW; break; case TOX_USERSTATUS_BUSY: colour = RED; break; case TOX_USERSTATUS_INVALID: colour = MAGENTA; break; } wattron(self->window, COLOR_PAIR(colour) | A_BOLD); wprintw(self->window, "%s ", ONLINE_CHAR); wattroff(self->window, COLOR_PAIR(colour) | A_BOLD); if (f_selected) wattron(self->window, COLOR_PAIR(BLUE)); wattron(self->window, A_BOLD); wprintw(self->window, "%s", friends[f].name); wattroff(self->window, A_BOLD); if (f_selected) wattroff(self->window, COLOR_PAIR(BLUE)); /* Reset friends[f].statusmsg on window resize */ if (fix_statuses) { char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; pthread_mutex_lock(&Winthread.lock); tox_get_status_message(m, friends[f].num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH); pthread_mutex_unlock(&Winthread.lock); snprintf(friends[f].statusmsg, sizeof(friends[f].statusmsg), "%s", statusmsg); friends[f].statusmsg_len = strlen(friends[f].statusmsg); } /* Truncate note if it doesn't fit on one line */ uint16_t maxlen = x2 - getcurx(self->window) - 2; if (friends[f].statusmsg_len > maxlen) { friends[f].statusmsg[maxlen - 3] = '\0'; strcat(friends[f].statusmsg, "..."); friends[f].statusmsg[maxlen] = '\0'; friends[f].statusmsg_len = maxlen; } if (friends[f].statusmsg[0]) wprintw(self->window, " %s", friends[f].statusmsg); wprintw(self->window, "\n"); } else { wprintw(self->window, "%s ", OFFLINE_CHAR); if (f_selected) wattron(self->window, COLOR_PAIR(BLUE)); wattron(self->window, A_BOLD); wprintw(self->window, "%s", friends[f].name); wattroff(self->window, A_BOLD); if (f_selected) wattroff(self->window, COLOR_PAIR(BLUE)); uint64_t last_seen = friends[f].last_online.last_on; if (last_seen != 0) { int day_dist = (cur_loc_tm.tm_yday - friends[f].last_online.tm.tm_yday) % 365; const char *hourmin = friends[f].last_online.hour_min_str; switch (day_dist) { case 0: wprintw(self->window, " Last seen: Today %s\n", hourmin); break; case 1: wprintw(self->window, " Last seen: Yesterday %s\n", hourmin); break; default: wprintw(self->window, " Last seen: %d days ago\n", day_dist); break; } } else { wprintw(self->window, " Last seen: Never\n"); } } } } self->x = x2; if (num_friends) { wmove(self->window, y2 - 1, 1); wattron(self->window, A_BOLD); wprintw(self->window, "ID: "); wattroff(self->window, A_BOLD); int i; for (i = 0; i < TOX_CLIENT_ID_SIZE; ++i) wprintw(self->window, "%02X", friends[selected_num].pub_key[i] & 0xff); } wrefresh(self->window); draw_del_popup(); if (self->help->active) help_onDraw(self); }
static void display_nav_sol(unsigned char *buf, size_t data_len) { unsigned short gw = 0; unsigned int tow = 0, flags; double epx, epy, epz, evx, evy, evz; unsigned char navmode; struct gps_data_t g; double separation; if (data_len != 52) return; navmode = (unsigned char)getub(buf, 10); flags = (unsigned int)getub(buf, 11); if ((flags & (UBX_SOL_VALID_WEEK | UBX_SOL_VALID_TIME)) != 0) { tow = (unsigned int)getleu32(buf, 0); gw = (unsigned short)getles16(buf, 8); } epx = (double)(getles32(buf, 12) / 100.0); epy = (double)(getles32(buf, 16) / 100.0); epz = (double)(getles32(buf, 20) / 100.0); evx = (double)(getles32(buf, 28) / 100.0); evy = (double)(getles32(buf, 32) / 100.0); evz = (double)(getles32(buf, 36) / 100.0); ecef_to_wgs84fix(&g.fix, &separation, epx, epy, epz, evx, evy, evz); g.fix.epx = g.fix.epy = (double)(getles32(buf, 24) / 100.0); g.fix.eps = (double)(getles32(buf, 40) / 100.0); g.dop.pdop = (double)(getleu16(buf, 44) / 100.0); g.satellites_used = (int)getub(buf, 47); (void)wmove(navsolwin, 1, 11); (void)wprintw(navsolwin, "%+10.2fm %+10.2fm %+10.2fm", epx, epy, epz); (void)wmove(navsolwin, 2, 11); (void)wprintw(navsolwin, "%+9.2fm/s %+9.2fm/s %+9.2fm/s", evx, evy, evz); (void)wmove(navsolwin, 4, 11); (void)wattrset(navsolwin, A_UNDERLINE); (void)wprintw(navsolwin, "%12.9f %13.9f %8.2fm", g.fix.latitude, g.fix.longitude, g.fix.altitude); (void)mvwaddch(navsolwin, 4, 23, ACS_DEGREE); (void)mvwaddch(navsolwin, 4, 38, ACS_DEGREE); (void)wmove(navsolwin, 5, 11); (void)wprintw(navsolwin, "%6.2fm/s %5.1fo %6.2fm/s", g.fix.speed, g.fix.track, g.fix.climb); (void)mvwaddch(navsolwin, 5, 26, ACS_DEGREE); (void)wattrset(navsolwin, A_NORMAL); (void)wmove(navsolwin, 7, 7); { unsigned int day = tow / 8640000; unsigned int tod = tow % 8640000; unsigned int h = tod / 360000; unsigned int m = tod % 360000; unsigned int s = m % 6000; m = (m - s) / 6000; (void)wattrset(navsolwin, A_UNDERLINE); (void)wprintw(navsolwin, "%u %02u:%02u:%05.2f", day, h, m, (double)s / 100); (void)wattrset(navsolwin, A_NORMAL); } (void)wmove(navsolwin, 8, 11); if ((flags & (UBX_SOL_VALID_WEEK | UBX_SOL_VALID_TIME)) != 0) { (void)wprintw(navsolwin, "%d+%10.3lf", gw, (double)(tow / 1000.0)); (void)wmove(navsolwin, 8, 36); (void)wprintw(navsolwin, "%d", (tow / 86400000)); } /* relies on the fact that epx and epy are set to same value */ (void)wmove(navsolwin, 10, 12); (void)wprintw(navsolwin, "%7.2f", g.fix.epx); (void)wmove(navsolwin, 10, 33); (void)wprintw(navsolwin, "%6.2f", g.fix.epv); (void)wmove(navsolwin, 11, 7); (void)wprintw(navsolwin, "%2d", g.satellites_used); (void)wmove(navsolwin, 11, 15); (void)wprintw(navsolwin, "%5.1f", g.dop.pdop); (void)wmove(navsolwin, 11, 25); (void)wprintw(navsolwin, "0x%02x", navmode); (void)wmove(navsolwin, 11, 36); (void)wprintw(navsolwin, "0x%02x", flags); (void)wnoutrefresh(navsolwin); }
/* * Display a menu for choosing among a number of options */ int dialog_menu(const char *title, const char *prompt, const void *selected, int *s_scroll) { int i, j, x, y, box_x, box_y; int height, width, menu_height; int key = 0, button = 0, scroll = 0, choice = 0; int first_item = 0, max_choice; WINDOW *dialog, *menu; do_resize: height = getmaxy(stdscr); width = getmaxx(stdscr); if (height < 15 || width < 65) return -ERRDISPLAYTOOSMALL; height -= 4; width -= 5; menu_height = height - 10; max_choice = MIN(menu_height, item_count()); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); (void)wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); (void)wattrset(dialog, dlg.dialog.atr); wbkgdset(dialog, dlg.dialog.atr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); (void)wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); menu_width = width - 6; box_y = height - menu_height - 5; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); keypad(menu, TRUE); /* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, dlg.menubox_border.atr, dlg.menubox.atr); if (menu_width >= 80) item_x = (menu_width - 70) / 2; else item_x = 4; /* Set choice to default item */ item_foreach() if (selected && (selected == item_data())) choice = item_n(); /* get the saved scroll info */ scroll = *s_scroll; if ((scroll <= choice) && (scroll + max_choice > choice) && (scroll >= 0) && (scroll + max_choice <= item_count())) { first_item = scroll; choice = choice - scroll; } else { scroll = 0; } if ((choice >= max_choice)) { if (choice >= item_count() - max_choice / 2) scroll = first_item = item_count() - max_choice; else scroll = first_item = choice - max_choice / 2; choice = choice - scroll; } /* Print the menu */ for (i = 0; i < max_choice; i++) { print_item(first_item + i, i, i == choice); } wnoutrefresh(menu); print_arrows(dialog, item_count(), scroll, box_y, box_x + item_x + 1, menu_height); print_buttons(dialog, height, width, 0); wmove(menu, choice, item_x + 1); wrefresh(menu); while (key != KEY_ESC) { key = wgetch(menu); if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynmh", key)) i = max_choice; else { for (i = choice + 1; i < max_choice; i++) { item_set(scroll + i); j = first_alpha(item_str(), "YyNnMmHh"); if (key == tolower(item_str()[j])) break; } if (i == max_choice) for (i = 0; i < max_choice; i++) { item_set(scroll + i); j = first_alpha(item_str(), "YyNnMmHh"); if (key == tolower(item_str()[j])) break; } } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { /* Remove highligt of current item */ print_item(scroll + choice, choice, FALSE); if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { /* Scroll menu down */ do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else choice = MAX(choice - 1, 0); } else if (key == KEY_DOWN || key == '+') { print_item(scroll+choice, choice, FALSE); if ((choice > max_choice - 3) && (scroll + max_choice < item_count())) { /* Scroll menu up */ do_scroll(menu, &scroll, 1); print_item(scroll+max_choice - 1, max_choice - 1, FALSE); } else choice = MIN(choice + 1, max_choice - 1); } else if (key == KEY_PPAGE) { scrollok(menu, TRUE); for (i = 0; (i < max_choice); i++) { if (scroll > 0) { do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else { if (choice > 0) choice--; } } } else if (key == KEY_NPAGE) { for (i = 0; (i < max_choice); i++) { if (scroll + max_choice < item_count()) { do_scroll(menu, &scroll, 1); print_item(scroll+max_choice-1, max_choice - 1, FALSE); } else { if (choice + 1 < max_choice) choice++; } } } else choice = i; print_item(scroll + choice, choice, TRUE); print_arrows(dialog, item_count(), scroll, box_y, box_x + item_x + 1, menu_height); wnoutrefresh(dialog); wrefresh(menu); continue; /* wait for another key press */ } switch (key) { case KEY_LEFT: case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 2 : (button > 2 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(menu); break; case ' ': case 's': case 'y': case 'n': case 'm': case '/': case 'h': case '?': case 'z': case '\n': /* save scroll info */ *s_scroll = scroll; delwin(menu); delwin(dialog); item_set(scroll + choice); item_set_selected(1); switch (key) { case 'h': case '?': return 2; case 's': case 'y': return 3; case 'n': return 4; case 'm': return 5; case ' ': return 6; case '/': return 7; case 'z': return 8; case '\n': return button; } return 0; case 'e': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(menu); break; case KEY_RESIZE: on_key_resize(); delwin(menu); delwin(dialog); goto do_resize; } } delwin(menu); delwin(dialog); return key; /* ESC pressed */ }
static bool ubx_initialize(void) { int i; /* "heavily inspired" by monitor_nmea.c */ if ((satwin = derwin(devicewin, 19, 28, 0, 0)) == NULL) return false; (void)wborder(satwin, 0, 0, 0, 0, 0, 0, 0, 0), (void)syncok(satwin, true); (void)wattrset(satwin, A_BOLD); display(satwin, 1, 1, "Ch PRN Az El S/N Flag U"); for (i = 0; i < 16; i++) display(satwin, (int)(i + 2), 1, "%2d", i); display(satwin, 18, 7, " NAV_SVINFO "); (void)wattrset(satwin, A_NORMAL); /* "heavily inspired" by monitor_nmea.c */ if ((navsolwin = derwin(devicewin, 13, 51, 0, 28)) == NULL) return false; (void)wborder(navsolwin, 0, 0, 0, 0, 0, 0, 0, 0), (void)wattrset(navsolwin, A_BOLD); (void)wmove(navsolwin, 1, 1); (void)wprintw(navsolwin, "ECEF Pos:"); (void)wmove(navsolwin, 2, 1); (void)wprintw(navsolwin, "ECEF Vel:"); (void)wmove(navsolwin, 4, 1); (void)wprintw(navsolwin, "LTP Pos:"); (void)wmove(navsolwin, 5, 1); (void)wprintw(navsolwin, "LTP Vel:"); (void)wmove(navsolwin, 7, 1); (void)wprintw(navsolwin, "Time:"); (void)wmove(navsolwin, 8, 1); (void)wprintw(navsolwin, "Time GPS: Day:"); (void)wmove(navsolwin, 10, 1); (void)wprintw(navsolwin, "Est Pos Err m Est Vel Err m/s"); (void)wmove(navsolwin, 11, 1); (void)wprintw(navsolwin, "PRNs: ## PDOP: xx.x Fix 0x.. Flags 0x.."); display(navsolwin, 12, 20, " NAV_SOL "); (void)wattrset(navsolwin, A_NORMAL); if ((dopwin = derwin(devicewin, 3, 51, 13, 28)) == NULL) return false; (void)wborder(dopwin, 0, 0, 0, 0, 0, 0, 0, 0); (void)wattrset(dopwin, A_BOLD); (void)wmove(dopwin, 1, 1); (void)wprintw(dopwin, "DOP [H] [V] [P] [T] [G]"); display(dopwin, 2, 20, " NAV_DOP "); (void)wattrset(dopwin, A_NORMAL); if ((ppswin = derwin(devicewin, 3, 51, 16, 28)) == NULL) return false; (void)wborder(ppswin, 0, 0, 0, 0, 0, 0, 0, 0); (void)wattrset(ppswin, A_BOLD); #define TOFF_LINE 1 #define TOFF_COLUMN 1 (void)mvwaddstr(ppswin, TOFF_LINE, TOFF_COLUMN, "TOFF: "); #ifndef PPS_ENABLE (void)mvwaddstr(ppswin, TOFF_LINE, TOFF_COLUMN + 10, "N/A"); #endif /* PPS_ENABLE */ #define PPS_LINE 1 #define PPS_COLUMN 26 (void)mvwaddstr(ppswin, PPS_LINE, PPS_COLUMN, "PPS: "); #ifndef PPS_ENABLE (void)mvwaddstr(ppswin, PPS_LINE, PPS_COLUMN + 10, "N/A"); #endif /* PPS_ENABLE */ (void)wattrset(ppswin, A_NORMAL); return true; }
void outputTest(WINDOW *win) { WINDOW *win1; char Buffer[80]; chtype ch; int by, bx; nl(); wclear(win); mvwaddstr(win, 1, 1, "You should now have a screen in the upper " "left corner, and this text should have wrapped"); waddstr(win,"\nThis text should be down\n"); waddstr(win, "and broken into two here ^"); Continue(win); wclear(win); wattron(win, A_BOLD); mvwaddstr(win, 1, 1, "A new window will appear with this text in it"); mvwaddstr(win, 8, 1, "Press any key to continue"); wrefresh(win); wgetch(win); getbegyx(win, by, bx); if (LINES < 24 || COLS < 75) { mvwaddstr(win, 5, 1, "Some tests have been skipped as they require a"); mvwaddstr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS"); Continue(win); } else { win1 = newwin(10, 50, 14, 25); if (win1 == NULL) { endwin(); return; } #ifdef A_COLOR if (has_colors()) { init_pair(3, COLOR_BLUE, COLOR_WHITE); wbkgd(win1, COLOR_PAIR(3)); } else #endif wbkgd(win1, A_NORMAL); wclear(win1); mvwaddstr(win1, 5, 1, "This text should appear; using overlay option"); copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE); box(win1, ACS_VLINE, ACS_HLINE); wmove(win1, 8, 26); wrefresh(win1); wgetch(win1); wclear(win1); wattron(win1, A_BLINK); mvwaddstr(win1, 4, 1, "This blinking text should appear in only the second window"); wattroff(win1, A_BLINK); mvwin(win1, by, bx); overlay(win, win1); mvwin(win1, 14, 25); wmove(win1, 8, 26); wrefresh(win1); wgetch(win1); delwin(win1); } clear(); wclear(win); wrefresh(win); mvwaddstr(win, 6, 2, "This line shouldn't appear"); mvwaddstr(win, 4, 2, "Only half of the next line is visible"); mvwaddstr(win, 5, 2, "Only half of the next line is visible"); wmove(win, 6, 1); wclrtobot(win); wmove(win, 5, 20); wclrtoeol(win); mvwaddstr(win, 8, 2, "This line also shouldn't appear"); wmove(win, 8, 1); winsdelln(win, -1); Continue(win); wmove(win, 5, 9); ch = winch(win); wclear(win); wmove(win, 6, 2); waddstr(win, "The next char should be l: "); winsch(win, ch); Continue(win); mvwinsstr(win, 6, 2, "A1B2C3D4E5"); Continue(win); wmove(win, 5, 1); winsdelln(win, 1); mvwaddstr(win, 5, 2, "The lines below should have moved down"); Continue(win); wclear(win); wmove(win, 2, 2); wprintw(win, "This is a formatted string in a window: %d %s\n", 42, "is it"); mvwaddstr(win, 10, 1, "Enter a string: "); wrefresh(win); echo(); wscanw(win, "%s", Buffer); printw("This is a formatted string in stdscr: %d %s\n", 42, "is it"); mvaddstr(10, 1, "Enter a string: "); scanw("%s", Buffer); wclear(win); curs_set(2); mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode"); Continue(win); wclear(win); curs_set(0); mvwaddstr(win, 1, 1, "The cursor should have disappeared"); Continue(win); wclear(win); curs_set(1); mvwaddstr(win, 1, 1, "The cursor should be normal"); Continue(win); #ifdef A_COLOR if (has_colors()) { wclear(win); mvwaddstr(win, 1, 1, "Colors should change after you press a key"); Continue(win); init_pair(1, COLOR_RED, COLOR_WHITE); wrefresh(win); } #endif werase(win); mvwaddstr(win, 1, 1, "Information About Your Terminal"); mvwaddstr(win, 3, 1, termname()); mvwaddstr(win, 4, 1, longname()); if (termattrs() & A_BLINK) mvwaddstr(win, 5, 1, "This terminal claims to support blinking."); else mvwaddstr(win, 5, 1, "This terminal does NOT support blinking."); mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16); wrefresh(win); mvwinnstr(win, 7, 5, Buffer, 18); mvaddstr(LINES - 2, 10, Buffer); refresh(); Continue(win); }
static void chat_onDraw(ToxWindow *self, Tox *m) { curs_set(1); int x2, y2; getmaxyx(self->window, y2, x2); ChatContext *ctx = self->chatwin; wclear(ctx->linewin); if (ctx->len > 0) { uint8_t line[MAX_STR_SIZE]; if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) { reset_buf(ctx->line, &ctx->pos, &ctx->len); wmove(self->window, y2 - CURS_Y_OFFSET, 0); } else { mvwprintw(ctx->linewin, 1, 0, "%s", line); } } /* Draw status bar */ StatusBar *statusbar = self->stb; mvwhline(statusbar->topline, 1, 0, ACS_HLINE, x2); wmove(statusbar->topline, 0, 0); /* Draw name, status and note in statusbar */ if (statusbar->is_online) { char *status_text = "Unknown"; int colour = WHITE; TOX_USERSTATUS status = statusbar->status; switch (status) { case TOX_USERSTATUS_NONE: status_text = "Online"; colour = GREEN; break; case TOX_USERSTATUS_AWAY: status_text = "Away"; colour = YELLOW; break; case TOX_USERSTATUS_BUSY: status_text = "Busy"; colour = RED; break; } wattron(statusbar->topline, A_BOLD); wprintw(statusbar->topline, " %s ", self->name); wattroff(statusbar->topline, A_BOLD); wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD); wprintw(statusbar->topline, "[%s]", status_text); wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD); } else { wattron(statusbar->topline, A_BOLD); wprintw(statusbar->topline, " %s ", self->name); wattroff(statusbar->topline, A_BOLD); wprintw(statusbar->topline, "[Offline]"); } /* Reset statusbar->statusmsg on window resize */ if (x2 != self->x) { uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'}; tox_get_status_message(m, self->num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH); snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg); statusbar->statusmsg_len = tox_get_status_message_size(m, self->num); } self->x = x2; /* Truncate note if it doesn't fit in statusbar */ uint16_t maxlen = x2 - getcurx(statusbar->topline) - 4; if (statusbar->statusmsg_len > maxlen) { statusbar->statusmsg[maxlen] = '\0'; statusbar->statusmsg_len = maxlen; } if (statusbar->statusmsg[0]) { wattron(statusbar->topline, A_BOLD); wprintw(statusbar->topline, " - %s ", statusbar->statusmsg); wattroff(statusbar->topline, A_BOLD); } wprintw(statusbar->topline, "\n"); mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x2); }