int dialog_inputbox(WINDOW *main_window, const char *title, const char *prompt, const char *init, char **resultp, int *result_len) { int prompt_lines = 0; int prompt_width = 0; WINDOW *win; WINDOW *prompt_win; WINDOW *form_win; PANEL *panel; int i, x, y; int res = -1; int cursor_position = strlen(init); int cursor_form_win; char *result = *resultp; if (strlen(init)+1 > *result_len) { *result_len = strlen(init)+1; *resultp = result = realloc(result, *result_len); } /* find the widest line of msg: */ prompt_lines = get_line_no(prompt); for (i = 0; i < prompt_lines; i++) { const char *line = get_line(prompt, i); int len = get_line_length(line); prompt_width = max(prompt_width, len); } if (title) prompt_width = max(prompt_width, strlen(title)); /* place dialog in middle of screen */ y = (LINES-(prompt_lines+4))/2; x = (COLS-(prompt_width+4))/2; strncpy(result, init, *result_len); /* create the windows */ win = newwin(prompt_lines+6, prompt_width+7, y, x); prompt_win = derwin(win, prompt_lines+1, prompt_width, 2, 2); form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2); keypad(form_win, TRUE); (void) wattrset(form_win, attributes[INPUT_FIELD]); (void) wattrset(win, attributes[INPUT_BOX]); box(win, 0, 0); (void) wattrset(win, attributes[INPUT_HEADING]); if (title) mvwprintw(win, 0, 3, "%s", title); /* print message */ (void) wattrset(prompt_win, attributes[INPUT_TEXT]); fill_window(prompt_win, prompt); mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); cursor_form_win = min(cursor_position, prompt_width-1); mvwprintw(form_win, 0, 0, "%s", result + cursor_position-cursor_form_win); /* create panels */ panel = new_panel(win); /* show the cursor */ curs_set(1); touchwin(win); refresh_all_windows(main_window); while ((res = wgetch(form_win))) { int len = strlen(result); switch (res) { case 10: /* ENTER */ case 27: /* ESCAPE */ case KEY_F(F_HELP): case KEY_F(F_EXIT): case KEY_F(F_BACK): break; case 127: case KEY_BACKSPACE: if (cursor_position > 0) { memmove(&result[cursor_position-1], &result[cursor_position], len-cursor_position+1); cursor_position--; cursor_form_win--; len--; } break; case KEY_DC: if (cursor_position >= 0 && cursor_position < len) { memmove(&result[cursor_position], &result[cursor_position+1], len-cursor_position+1); len--; } break; case KEY_UP: case KEY_RIGHT: if (cursor_position < len) { cursor_position++; cursor_form_win++; } break; case KEY_DOWN: case KEY_LEFT: if (cursor_position > 0) { cursor_position--; cursor_form_win--; } break; case KEY_HOME: cursor_position = 0; cursor_form_win = 0; break; case KEY_END: cursor_position = len; cursor_form_win = min(cursor_position, prompt_width-1); break; default: if ((isgraph(res) || isspace(res))) { /* one for new char, one for '\0' */ if (len+2 > *result_len) { *result_len = len+2; *resultp = result = realloc(result, *result_len); } /* insert the char at the proper position */ memmove(&result[cursor_position+1], &result[cursor_position], len-cursor_position+1); result[cursor_position] = res; cursor_position++; cursor_form_win++; len++; } else { mvprintw(0, 0, "unknown key: %d\n", res); } break; } if (cursor_form_win < 0) cursor_form_win = 0; else if (cursor_form_win > prompt_width-1) cursor_form_win = prompt_width-1; wmove(form_win, 0, 0); wclrtoeol(form_win); mvwprintw(form_win, 0, 0, "%*s", prompt_width, " "); mvwprintw(form_win, 0, 0, "%s", result + cursor_position-cursor_form_win); wmove(form_win, 0, cursor_form_win); touchwin(win); refresh_all_windows(main_window); if (res == 10) { res = 0; break; } else if (res == 27 || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) { res = KEY_EXIT; break; } else if (res == KEY_F(F_HELP)) { res = 1; break; } } /* hide the cursor */ curs_set(0); del_panel(panel); delwin(prompt_win); delwin(form_win); delwin(win); return res; }
int keyer(void) { extern int cqmode; extern char mode[20]; extern char message[][80]; extern char wkeyerbuffer[]; extern int data_ready; extern int keyerport; extern int weight; WINDOW *win = NULL; PANEL *panel = NULL; int x = 0, j = 0; int cury, curx; char nkbuffer[2]; char keyerstring[KEYER_LINE_WIDTH+1] = ""; int keyerstringpos = 0; char weightbuf[15]; const char txcontrolstring[2] = { 20, '\0' }; // ^t const char rxcontrolstring[2] = { 18, '\0' }; // ^r const char crcontrolstring[2] = { 13, '\0' }; // cr const char ctl_c_controlstring[2] = { 92, '\0' }; // '\' if (keyerport == NO_KEYER) /* no keyer present */ return 1; strcpy(mode, "Keyboard"); clear_display(); attron(COLOR_PAIR(C_LOG) | A_STANDOUT); if (panel == NULL) { win = newwin(KEYER_WIN_HEIGHT, KEYER_WIN_WIDTH, KEYER_Y, KEYER_Y ); if (win == NULL) return 1; panel = new_panel(win); if (panel == NULL) { delwin(win); return 1; } } show_panel(panel); werase(win); wnicebox(win, 0, 0, 1, KEYER_LINE_WIDTH, "CW Keyer"); if (keyerport == MFJ1278_KEYER) { if (data_ready != 1) { /* switch to tx */ strcat(wkeyerbuffer, txcontrolstring); data_ready = 1; } } while (1) { wattron(win, COLOR_PAIR(C_LOG) | A_STANDOUT); wmove (win, 1, 1); for (j = 0; j < KEYER_LINE_WIDTH; j++) { waddch (win, ' '); } mvwprintw(win, 1, 1, "%s", keyerstring); refreshp(); x = key_get(); // Send space instead of double quote. if (x == 34) { x = 32; } // Send space instead of newline or return. if (x == '\n' || x == KEY_ENTER) x = 32; // <Escape>, Ctrl-K (^K), Alt-k (M-k) if (x == 27 || x == 11 || x == 235) { if (keyerport == MFJ1278_KEYER) { if (data_ready != 1) { /* switch back to rx */ strcat(wkeyerbuffer, rxcontrolstring); data_ready = 1; } } else { stoptx(); } break; } // Promote lower case to upper case. if (x > 96 && x < 123) x = x - 32; if (x > 9 && x < 91) { /* drop all other control char... */ if (x > 31 || x == 10) { if (keyerport == MFJ1278_KEYER) { mfj1278_control(x); } else if (keyerport == NET_KEYER) { nkbuffer[0] = x; // 1 char at the time ! nkbuffer[1] = '\0'; netkeyer(K_MESSAGE, nkbuffer); } /* if display field is full move text one left */ if (keyerstringpos == KEYER_LINE_WIDTH - 1) { for (j = 0; j < KEYER_LINE_WIDTH - 1; j++) { keyerstring[j] = keyerstring[j + 1]; } keyerstringpos--; } /* add new character for display */ keyerstring[keyerstringpos++] = x; keyerstring[keyerstringpos] = '\0'; } } else { switch (x) { case '\n': case 13: case KEY_ENTER: { if (keyerport == MFJ1278_KEYER) { sendmessage(crcontrolstring); } break; } case 123: /* { */ { if (keyerport == MFJ1278_KEYER) { sendmessage(txcontrolstring); } break; } case 125: /* } */ { if (keyerport == MFJ1278_KEYER) { sendmessage(rxcontrolstring); } break; } case 92: /* \ */ { if (keyerport == MFJ1278_KEYER) { sendmessage(ctl_c_controlstring); } break; } case 247: // Alt-w, set weight { mvprintw(1, 0, "Weight= "); mvprintw(1, 7, ""); refreshp(); echo(); getnstr(weightbuf, 2); noecho(); weight = atoi(weightbuf); netkeyer(K_WEIGHT, weightbuf); break; } // <Page-Up>, increase CW speed. case KEY_PPAGE: { speedup(); clear_display(); break; } // <Page-Down>, decrease CW speed. case KEY_NPAGE: { speeddown(); clear_display(); break; } case KEY_F(1): { getyx(stdscr, cury, curx); mvprintw(5, 0, ""); sendmessage(message[0]); /* F1 */ mvprintw(cury, curx, ""); break; } case KEY_F(2): { sendmessage(message[1]); /* F2 */ break; } case KEY_F(3): { sendmessage(message[2]); /* F3 */ break; } case KEY_F(4): { sendmessage(message[3]); /* F4 */ break; } case KEY_F(5): { sendmessage(message[4]); /* F5 */ break; } case KEY_F(6): { sendmessage(message[5]); /* F6 */ break; } case KEY_F(7): { sendmessage(message[6]); /* F7 */ break; } case KEY_F(8): { sendmessage(message[7]); /* F8 */ break; } case KEY_F(9): { sendmessage(message[8]); /* F9 */ break; } case KEY_F(10): { sendmessage(message[9]); /* F10 */ break; } case KEY_F(11): { sendmessage(message[10]); /* F11 */ break; } case KEY_F(12): { sendmessage(message[11]); /* F12 */ break; } default: x = x; } } } hide_panel(panel); if (cqmode == CQ) strcpy(mode, "Log "); else strcpy(mode, "S&P "); clear_display(); return 0; /* show end of keyer routine */ }
static void browse_draw_item(struct dir *n, int row) { char ct, dt, *size, gr[11]; int i, o; float pc; if(n->flags & FF_BSEL) attron(A_REVERSE); /* reference to parent dir has a different format */ if(n == dirlist_parent) { mvhline(row, 0, ' ', wincols); o = graph == 0 ? 12 : graph == 1 ? 24 : graph == 2 ? 20 : 31 ; mvaddstr(row, o, "/.."); if(n->flags & FF_BSEL) attroff(A_REVERSE); return; } /* determine indication character */ ct = n->flags & FF_EXL ? '<' : n->flags & FF_ERR ? '!' : n->flags & FF_SERR ? '.' : n->flags & FF_OTHFS ? '>' : n->flags & FF_HLNKC ? 'H' : !(n->flags & FF_FILE || n->flags & FF_DIR) ? '@' : n->flags & FF_DIR && n->sub == NULL ? 'e' : ' ' ; dt = n->flags & FF_DIR ? '/' : ' '; size = formatsize(show_as ? n->asize : n->size); /* create graph (if necessary) */ if(graph) { /* percentage */ if((pc = (float)(show_as ? n->parent->asize : n->parent->size)) < 1) pc = 1.0f; pc = ((float)(show_as ? n->asize : n->size) / pc) * 100.0f; /* graph */ if(graph == 1 || graph == 3) { o = (int)(10.0f*(float)(show_as ? n->asize : n->size) / (float)(show_as ? dirlist_maxa : dirlist_maxs)); for(i=0; i<10; i++) gr[i] = i < o ? '#' : ' '; gr[10] = '\0'; } } /* format and add item to the list */ switch(graph) { case 0: mvprintw(row, 0, "%c %8s %c%-*s", ct, size, dt, wincols-13, cropstr(n->name, wincols-13)); break; case 1: mvprintw(row, 0, "%c %8s [%10s] %c%-*s", ct, size, gr, dt, wincols-25, cropstr(n->name, wincols-25)); break; case 2: mvprintw(row, 0, "%c %8s [%5.1f%%] %c%-*s", ct, size, pc, dt, wincols-21, cropstr(n->name, wincols-21)); break; case 3: mvprintw(row, 0, "%c %8s [%5.1f%% %10s] %c%-*s", ct, size, pc, gr, dt, wincols-32, cropstr(n->name, wincols-32)); } if(n->flags & FF_BSEL) attroff(A_REVERSE); }
/******************************************************************************* * Description: waits for key stroke input, or until timeout occurs * * Inputs: void * * Returns: integer value following the direction definition ******************************************************************************/ int readInput( void ) { int direction; bool flag = true, flag2 = false; while( flag || flag2 ) { int pressedKey = getch(); if( PREV_KEY == pressedKey && (pressedKey == 65 || pressedKey == 66 || pressedKey == 67 || pressedKey == 68) ) { return PREV_DIRECTION; } else { PREV_KEY = pressedKey; } switch( pressedKey ) { case 65: // up direction = 0; flag = false; break; case 67: // right direction = 1; flag = false; break; case 66: // down direction = 2; flag = false; break; case 68: // left direction = 3; flag = false; break; case 112: // [p]ause if( !flag2 ) { timeout( 900000 ); // after 15 minutes of pause, just go mvprintw( MAX_ROW-1, (MAX_COL-7)/2, "Paused!" ); flag2 = true; } else { timeout( TIMEOUT ); mvprintw( MAX_ROW-1, (MAX_COL-7)/2, " " ); flag2 = false; return PREV_DIRECTION; } break; case 113: // [q]uit direction = -2; return -2; break; case 114: // [r]estart setup(); return 4; break; case ERR: // -1 direction = 4; flag = false; break; default: break; } /* char temp[128]; sprintf( temp, "echo %d >> keysPressed", pressedKey ); system( temp ); */ } return direction; }
static void curses_print_pv (const char * file, struct pv_complex * pv, int flag_play, long frame0, long frame1, double pv_pitch, double pv_rate) { mvprintw (0, 0, "========== pv =========="); mvprintw (Y_file, 1, "file : %s", file); mvprintw (Y_frames, 1, "current : %010ld / %010ld", 0, pv->sfinfo->frames); mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); /* mvprintw (Y_pitch, 1, "pitch : %-5.0f", pv_pitch); */ curses_print_pitch (pv_pitch); mvprintw (Y_rate, 1, "rate : %-5.1f", pv_rate); mvprintw (Y_len, 1, "fft-len : %06ld", pv->len); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); if (flag_play == 0) mvprintw(Y_status, 1, "status : stop"); else mvprintw(Y_status, 1, "status : play"); if (pv->flag_lock == 0) mvprintw(Y_lock, 1, "phase-lock : off"); else mvprintw(Y_lock, 1, "phase-lock : on "); if (flag_nofft == 0) mvprintw(Y_lock, 21, " "); else mvprintw(Y_lock, 21, "no-FFT"); curses_print_window (pv->flag_window); /* help message */ mvprintw (Y_loop, 41, "< > by cur, [ { expand } ]"); mvprintw (Y_pitch, 41, "UP / DOWN"); mvprintw (Y_rate, 41, "LEFT / RIGHT"); mvprintw (Y_hop_syn, 41, "H / h"); mvprintw (Y_status, 41, "SPACE"); mvprintw (Y_lock, 41, "L / N"); mvprintw (Y_window, 41, "W"); mvprintw (Y_comment - 1, 0, "----------------------------------------"); }
int main(int argc,char *argv[]){ srand(time(0)); printf("Space v0.1 coded by Zach Gunn.\n"); bool running = true; bool jumped = false; bool fired = false; int ch; Player ship; ship.x = 1; ship.y = 1; strcpy(ship.character,"@"); ship.max_shields = 50; ship.shields = ship.max_shields; ship.max_hull = 20; ship.hull = ship.max_hull; ship.max_power = 100; ship.power = ship.max_power; ship.missiles = 10; ship.max_missiles = 15; ship.facing = 's'; ship.score = 0; Ammo missile; missile.payload = rand()%50; Asteroid asteroid; asteroid.x = rand()%10+1; asteroid.y = rand()%50+1; asteroid.density = rand()%50+1; strcpy(asteroid.character,"#"); Station station; station.x = rand()%10+1; station.y = rand()%50+1; station.ammo_load = rand()%3+1; station.shield_load = rand()%40; station.repair_load = rand()%5; station.full = true; strcpy(station.character,"R"); initscr(); curs_set(FALSE); keypad(stdscr,TRUE); noecho(); while(running){ ship.shield_percent = (ship.shields/ship.max_shields)*100; if(ship.shield_percent <= 0){ ship.shield_percent = 0; } if(ship.shields <= 0){ ship.shields = 0; } if(ship.power <= 0){ ship.power = 0; } if(ship.hull <= 0){ ship.hull = 0; clear(); endwin(); printf("\nYour spaceship has been destroyed!\nYour final score was %d\n\n",ship.score); exit(0); } if(ship.power < ship.max_power && jumped == false){ if(fired == false){ ship.power++; }else{ fired = false; } }else{ jumped = false; } if(ship.shields >= ship.max_shields){ ship.shields = ship.max_shields; } if(ship.hull >= ship.max_hull){ ship.hull = ship.max_hull; } if(ship.missiles >= ship.max_missiles){ ship.missiles = ship.max_missiles; } clear(); mvprintw(0,0,"Hull: %.2f Shields: %.2f (%.2f%) Power: %.2f/%.0f X:%d Y:%d Missiles: %d Facing: %c\tScore: %d",ship.hull,ship.shields,ship.shield_percent,ship.power,ship.max_power,ship.x,ship.y,ship.missiles,ship.facing,ship.score); mvprintw(ship.x,ship.y,ship.character); if(asteroid.density >= 0){ if((rand()%100+1) <= 15 && asteroid.x != 21){ asteroid.x++; } if((rand()%100+1) <= 15 && asteroid. x != 1){ asteroid.x--; } if((rand()%100+1) <= 15 && asteroid.y != 61){ asteroid.y++; } if((rand()%100+1) <= 15 && asteroid.y != 1){ asteroid.y--; } mvprintw(asteroid.x,asteroid.y,asteroid.character); }else{ asteroid.x = rand()%10+1; asteroid.y = rand()%50+1; asteroid.density = rand()%100+1; } if(station.full == true){ mvprintw(station.x,station.y,station.character); } else if((rand()%100+1) <= 1){ station.x = rand()%10+1; station.y = rand()%50+1; station.ammo_load = rand()%3+1; station.shield_load = rand()%40; station.repair_load = rand()%5; station.full = true; } refresh(); ch = getch(); if(ch == KEY_UP && ship.x != 1){ ship.x--; ship.facing = 'n'; } if(ch == KEY_DOWN && ship.x != 21){ ship.x++; ship.facing = 's'; } if(ch == KEY_RIGHT && ship.y != 61){ ship.y++; ship.facing = 'e'; } if(ch == KEY_LEFT && ship.y != 1){ ship.y--; ship.facing = 'w'; } if(ch == 'f' && ship.missiles > 0){ missile.payload = rand()%50+1; int m=0; missile.x = ship.x; missile.y = ship.y; if(ship.facing == 'n'){ strcpy(missile.character,"|"); ship.missiles--; while(m<=7){ missile.x--; mvprintw(missile.x,missile.y,missile.character); if(missile.x == asteroid.x && missile.y == asteroid.y){ asteroid.density -= missile.payload; ship.score++; } refresh(); usleep(50000); m++; } } if(ship.facing == 'e'){ ship.missiles--; strcpy(missile.character,"-"); while(m<=7){ missile.y++; mvprintw(missile.x,missile.y,missile.character); if(missile.x == asteroid.x && missile.y == asteroid.y){ asteroid.density -= missile.payload; ship.score++; } refresh(); usleep(50000); m++; } } if(ship.facing == 's'){ ship.missiles--; strcpy(missile.character,"|"); while(m<=7){ missile.x++; mvprintw(missile.x,missile.y,missile.character); if(missile.x == asteroid.x && missile.y == asteroid.y){ asteroid.density -= missile.payload; ship.score++; } refresh(); usleep(50000); m++; } } if(ship.facing == 'w'){ ship.missiles--; strcpy(missile.character,"-"); while(m<=7){ missile.y--; mvprintw(missile.x,missile.y,missile.character); if(missile.x == asteroid.x && missile.y == asteroid.y){ asteroid.density -= missile.payload; ship.score++; } refresh(); usleep(50000); m++; } } fired = true; } if(ch == 'j' && ship.power >= 10){ if(ship.facing == 'n'){ ship.x -= 5; ship.power -= 10; refresh(); } if(ship.facing == 'e'){ ship.y += 5; ship.power -= 10; refresh(); } if(ship.facing == 's'){ ship.x += 5; ship.power -= 10; refresh(); } if(ship.facing == 'w'){ ship.y -= 5; ship.power -= 10; refresh(); } jumped = true; } if(ship.x == asteroid.x && ship.y == asteroid.y){ if(ship.shields > 0){ ship.shields -= asteroid.density; }else{ ship.hull -= asteroid.density*1.5; } } if(ship.x == station.x && ship.y == station.y){ ship.missiles += station.ammo_load; if(ship.shields < ship.max_shields){ ship.shields += station.shield_load; } if(ship.hull < ship.max_hull){ ship.hull += station.repair_load; } station.full = false; } } endwin(); }
/* * @brief Show different game and wait for user to choose * @return game The new game created */ static game select_game() { int row, col; int pos = 0; int ch = 0; game newGame = NULL; while (ch != '\n') { clear(); getmaxyx(stdscr, row, col); mvprintw(row / 2, col / 2 - 20, "Use arrow key to select your game"); if (pos == 0) { mvprintw(row / 2 + 1, col / 2 - 20, "-> Rush Hour"); mvprintw(row / 2 + 2, col / 2 - 20, " Ane rouge"); } else { mvprintw(row / 2 + 1, col / 2 - 20, " Rush Hour"); mvprintw(row / 2 + 2, col / 2 - 20, "-> Ane rouge"); } ch = getch(); if (ch == KEY_UP) { if (pos > 0) pos--; } else if (ch == KEY_DOWN) { if (pos < 1) pos++; } refresh(); } if (pos == 0) { //Rush hour piece pieces[4]; pieces[0] = new_piece_rh(3, 3, true, true); pieces[1] = new_piece_rh(3, 0, true, false); pieces[2] = new_piece_rh(4, 1, true, true); pieces[3] = new_piece_rh(5, 3, false, false); newGame = new_game(6, 6, 4, pieces); MAXCOL = game_width(newGame); MAXROW = game_height(newGame); MINH = MAXROW * SIZE + 2; MINW = MAXCOL * SIZE; game_over = game_over_hr; gameOverRh = true; for (int i = 0; i < game_nb_pieces(newGame); i++) { delete_piece(pieces[i]); } clear(); refresh(); return newGame; } else { //Ane rouge piece pieces[10]; pieces[0] = new_piece(1, 3, 2, 2, true, true); //Rouge pieces[1] = new_piece(3, 3, 1, 2, true, true); // 2 pieces[2] = new_piece(3, 1, 1, 2, true, true); // 3 pieces[3] = new_piece(3, 0, 1, 1, true, true); // 4 pieces[4] = new_piece(1, 2, 2, 1, true, true); // 5 pieces[5] = new_piece(2, 1, 1, 1, true, true); // 6 pieces[6] = new_piece(1, 1, 1, 1, true, true); // 7 pieces[7] = new_piece(0, 0, 1, 1, true, true); // 8 pieces[8] = new_piece(0, 1, 1, 2, true, true); // 9 pieces[9] = new_piece(0, 3, 1, 2, true, true); // 10 newGame = new_game(4, 5, 10, pieces); MAXCOL = game_width(newGame); MAXROW = game_height(newGame); MINH = MAXROW * SIZE + 2; MINW = MAXCOL * SIZE; game_over = game_over_an; gameOverRh = false; for (int i = 0; i < game_nb_pieces(newGame); i++) { delete_piece(pieces[i]); } clear(); refresh(); return newGame; } }
void display_wormhole(void) { mvprintw(space.wormhole_y, space.wormhole_x, space.wormhole); mvprintw(1,5, "wormhole at (%i,%i)", space.wormhole_x, space.wormhole_y); }
void count_moves(void) { hud.moves++; mvprintw(0, 50, "Moves: %d", hud.moves); }
int xyControl() { define_key("\033Op", 1000); define_key("\033Oq", 1001); define_key("\033Or", 1002); define_key("\033Os", 1003); define_key("\033Ot", 1004); define_key("\033Ou", 1005); define_key("\033Ov", 1006); define_key("\033Ow", 1007); define_key("\033Ox", 1008); define_key("\033Oy", 1009); // non-arrow keypad keys (for macros) define_key("\033OM", 1010); // Enter define_key("\033OP", 1011); // NumLock define_key("\033OQ", 1012); // / define_key("\033OR", 1013); // * define_key("\033OS", 1014); // - define_key("\033Oj", 1015); // * define_key("\033Ok", 1016); // + define_key("\033Ol", 1017); // + define_key("\033Om", 1018); // . define_key("\033On", 1019); // . define_key("\033Oo", 1020); // - clearScreen(); echo(); curs_set(2); int Xdist = 0; int Ydist = 0; while(!quit) { //must be acuroind to servoblaster wiring convention move(10,0); clrtoeol(); move(14,0); clrtoeol(); refresh(); mvprintw(10,5,"Curent Position: X:%d\tY:%d",posX,posY); mvprintw(14,5,"Move:"); mvprintw(14,12,"X:%d",Xdist); mvprintw(14,22,"Y:%d",Ydist); move(14,14); refresh(); char valueString [6]; char c = getch(); if(c=='q'||c=='Q') return 0; if(c!='\n') { printw(" "); refresh(); ungetch(c); move(14,14); getnstr(valueString,6); Xdist = atoi(valueString); } move(14,24); c = getch(); if(c=='q'||c=='Q') return 0; if(c!='\n') { printw(" "); refresh(); ungetch(c); move(14,24); getnstr(valueString,6); Ydist = atoi(valueString); } move(15,4); clrtoeol; //getch(); mvprintw(15,5,"MOVING X:%d, Y:%d ",Xdist,Ydist); refresh(); posX +=Xdist; posY +=Ydist; moveXY(Xdist,Ydist); } }
void initalize() { pinMode(Xstop,INPUT); pinMode(Ystop,INPUT); pinMode(motorXA,OUTPUT); pinMode(motorXB,OUTPUT); pinMode(motorYA,OUTPUT); pinMode(motorYB,OUTPUT); power(motorXA,0); power(motorXB,0); power(motorYA,0); power(motorYB,0); clearScreen(); keypad(stdscr,TRUE); bool stop = false; while(!quit&&!stop) { mvprintw(4,10,"Initalizing ...."); mvprintw(5,10,"Please use Page Up and Page Down Arrows to move the pen to just touching the page,When centered hit 'q'"); pen(STOPPULSE); int c = getch(); switch(c) { case KEY_NPAGE: pen(250); safeDelay(30); break; case KEY_PPAGE: pen(50); safeDelay(30); break; case 'q': case 'Q': pen(50); safeDelay(200); stop = true; break; defaut: break; } } penMove(1); move(5,0); clrtoeol(); nodelay(stdscr,0); mvprintw(5,10,"Finding position 0 on X axis..."); getch(); refresh(); if(digitalRead(Xstop)) { power(motorXA,100); safeDelay(500); power(motorXA,0); } clrtoeol(); mvprintw(5,10,"Finding position 0 on X axis..."); getch(); refresh(); power(motorXB,50); while(!quit&&!digitalRead(Xstop)) delay(3); posX=0; power(motorXB,0); printw("just found 0 on the x!"); getch(); if(digitalRead(Ystop)) { power(motorYA,100); safeDelay(500); power(motorYA,0); } power(motorYB,100); while(!quit&&!digitalRead(Ystop)) safeDelay(1); posY=0; power(motorYB,0); allSTOP(); }
int optoControl() { clearScreen(); keypad(stdscr,TRUE); bool isback = false; int xticks = 0; int yticks = 0; while(!quit) { keypad(stdscr,TRUE); nodelay(stdscr,1); noecho(); getch(); getch(); int c = getch(); mvprintw(8,5,"Press arrow key to change direction right now we are counting ticks %s, \n\tRight arrow to count up and left arrow to count down",(isback)?"down":"up"); move(14,0); clrtoeol(); mvprintw(14,10,"\tX-Ticks:%d\tY-Ticks:%d",xticks,yticks); refresh(); while(!quit && c == ERR) { int result = didTick(1,1); // delay(1); safeDelay(1); c=getch(); if(result==0) continue; if(result==1) xticks=(isback)?xticks-1:xticks+1; if(result==-1) yticks=(isback)?yticks-1:yticks+1; move(14,0); clrtoeol(); mvprintw(14,10,"\tX-Ticks:%d\tY-Ticks:%d\tXSTOP:%i",xticks,yticks,digitalRead(Xstop)); refresh(); } move(20,0); clrtoeol(); switch(c) { case 'q': case 'Q': mvprintw(20,3,"Quit has been pressed!"); return 0; break; case 'r': xticks = 0; yticks = 0; break; case KEY_RIGHT: mvprintw(20,3,"Right arrrow pressed!"); isback = 0; break; case KEY_LEFT: mvprintw(20,3,"LEFT Arrow pressed!"); isback = 1; break; default: mvprintw(24, 3, "Charcter pressed is = %3d Hopefully it can be printed as '%c'", c, c); refresh(); break; } // delay(10); safeDelay(10); refresh(); } return 0; }
int manualControl() { clearScreen(); mvprintw(3,0,"\tUP--Up Arrow\tDown--Down Arrow\tLeft--Left Arrow\tRight--Right Arrow\t\t\t\tPen Up--Page Up\t\tPen Down--Page Down"); refresh(); keypad(stdscr,TRUE); int choice = 0; while(!quit) { nodelay(stdscr,1); // noecho(); int c = getch(); while(!quit&& c == ERR) { pen(STOPPULSE); safeDelay(15); c = getch(); } switch(c) { case KEY_UP: if(DEBUG) mvprintw(20,3,"Up arrrow pressed!"); power(motorXA,100); power(motorXB,0); delay(20); power(motorXA,0); // movex(50); break; case KEY_DOWN: if(DEBUG) mvprintw(20,3,"Down arrrow pressed!"); power(motorXB,100); power(motorXA,0); delay(20); power(motorXB,0); break; case 'q': case 'Q': if(DEBUG) mvprintw(20,3,"Quit has been pressed!"); choice = 1; break; case KEY_LEFT: if(DEBUG) mvprintw(20,3,"Left arrrow pressed!"); power(motorYB,100); power(motorYA,0); delay(20); power(motorYB,0); break; case KEY_RIGHT: if(DEBUG) mvprintw(20,3,"Right arrrow pressed!"); power(motorYA,100); power(motorYB,0); delay(20); power(motorYA,0); break; case KEY_NPAGE: if(DEBUG) mvprintw(20,3,"Page Up arrrow pressed!"); penMove(1); break; case KEY_PPAGE: if(DEBUG) mvprintw(20,3,"Page down arrrow pressed!"); penMove(0); break; default: mvprintw(24, 3, "Charcter pressed is = %3d Hopefully it can be printed as '%c'", c, c); refresh(); break; } refresh(); if(choice != 0) /* User did a choice come out of the infinite loop */ break; } pen(150); return 0; }
int servoControl() { clearScreen(); mvprintw(3,0,"Servo control to manual mess with the timing of the servo, enter a value then hit enter and use right arrow to execute the value and hit backspace to got back to change the value"); refresh(); keypad(stdscr,TRUE); int choice = 0; while(!quit) { echo(); nodelay(stdscr,0); move(13,0); clrtoeol(); mvprintw(13,15,"Value to run at:"); char valueString [5]; getnstr(valueString,5); int value = atoi(valueString); choice = 0; mvprintw(14,12,"Value entered: %i",value); while(!quit&&choice == 0) { keypad(stdscr,TRUE); nodelay(stdscr,1); // noecho(); int c = getch(); while(!quit&& c == ERR) { pen(STOPPULSE); safeDelay(15); c = getch(); } switch(c) { case 'q': case 'Q': mvprintw(20,3,"Quit has been pressed!"); choice = 1; break; case KEY_RIGHT: mvprintw(20,3,"Right arrrow pressed!"); pen(value); safeDelay(30); break; case KEY_BACKSPACE: mvprintw(20,3,"BackSpace pressed!"); clrtoeol(); choice = 2; break; default: mvprintw(24, 3, "Charcter pressed is = %3d Hopefully it can be printed as '%c'", c, c); refresh(); break; } refresh(); if(choice != 0) /* User did a choice come out of the infinite loop */ break; } if(choice == 1) break; } pen(150); return 0; }
void Clock::updateClock(){ displayDate(); mvprintw(0,0,"F1-Military Time F3-Show seconds F6-Enter/Exit time set mode Esc- exit clock"); mvprintw(1,0,"F7-Time <-> Alarm in set mode F8-Hour+1 F9-Hour-1 F10-Minute +1 F11-Minute -1"); mvprintw(2,0,"Space Bar- gives 10 minute snooze time Enter- on/off alarm"); attron(COLOR_PAIR(1)); if (alarmOn) mvprintw(8,69," "); attroff(COLOR_PAIR(1)); attron(COLOR_PAIR(0)); if (!alarmOn) mvprintw(8,69," "); attroff(COLOR_PAIR(0)); mvprintw(8,72,"alarm on"); switch(mode){ case CLOCK: clockMode(); attron(COLOR_PAIR(0)); mvprintw(4, 69, " "); attroff(COLOR_PAIR(0)); display(&clockTime); break; case TIME_SET: clockMode(); if( (clockTime.tm_sec%2) || !blink ) display(&clockTime); else clear(); attron(COLOR_PAIR(1)); mvprintw(4, 69, " "); attroff(COLOR_PAIR(1)); mvprintw(4, 72, "set-mode"); break; case ALARM: clockMode(); attron(COLOR_PAIR(0)); mvprintw(4, 69, " "); attroff(COLOR_PAIR(0)); display(&alarm); break; case ALARM_SET: clockMode(); attron(COLOR_PAIR(1)); mvprintw(4, 69, " "); attroff(COLOR_PAIR(1)); mvprintw(4,72,"set-mode"); display(&alarm); break; } }
void aftershot(int y, int x) { probe_delay(); mvprintw(y, x, fire.blank); show_stars(); }
static void display_scores(t_all *all) { mvprintw(all->env.col - 3, 5, "Score : %d", all->env.score); }
void game_over(int y, int x) { int i = 1, j = LINES, fr; attrset(A_BOLD); mvprintw(y, x, aircraft.ship); getch(); mvprintw(y, x, space.blank); srand((unsigned)time(NULL)); while (i < (LINES / 2 - 2)) { ++i; j--; fr = (rand() % 150) + 100; sndon(fr); mvprintw(i, (COLS / 2 - 30), space.blank); mvprintw(i + 1, (COLS / 2 - 30), "G"); mvprintw(i, (COLS / 2 - 20), space.blank); mvprintw(i + 1, (COLS / 2 - 20), "A"); mvprintw(i, (COLS / 2 - 10), space.blank); mvprintw(i + 1, (COLS / 2 - 10), "M"); mvprintw(i, (COLS / 2), space.blank); mvprintw(i + 1, (COLS / 2), "E"); mvprintw(j, (COLS / 2 - 30), space.blank); mvprintw(j - 1, (COLS / 2 - 30), "O"); mvprintw(j, (COLS / 2 - 20), space.blank); mvprintw(j - 1, (COLS / 2 - 20), "V"); mvprintw(j, (COLS / 2 - 10), space.blank); mvprintw(j - 1, (COLS / 2 - 10), "E"); mvprintw(j, (COLS / 2), space.blank); mvprintw(j - 1, (COLS / 2), "R"); napms(100); refresh(); } sndoff(); nocbreak(); getch(); attrset(A_NORMAL); refresh(); flushinp(); endwin(); exit(0); }
int main(int argc, char *argv[]) { WINDOW *my_win, *score; WINDOW **car; game newGame, tmpGame; MEVENT event; int ch = 0, choosenCar = -1, soluce_move = 0; char message[1024]; bool quit = false; bool show_solution = false; gameStruct *resultSolv = NULL; //INIT setup(); //END INIT //Wait for good size wait_for_size(MINH, MINW); //Instruction show_instruction(MINH, MINW); while (!quit) { quit = false; show_solution = false; soluce_move = 0; strcpy(message, "Playing"); //Select game newGame = select_game(); //Check for level file if (handle_level(&tmpGame)) { delete_game(newGame); newGame = tmpGame; MAXCOL = game_width(newGame); MAXROW = game_height(newGame); MINH = MAXROW * SIZE + 2; MINW = MAXCOL * SIZE; } car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame)); //First draw draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh); //Loop while the game is not finished while (!game_over(newGame)) { //Print on bottom of grid mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :"); ch = getch(); if (ch == 's' && !show_solution) { show_solution = true; strcpy(message, "Solution"); resultSolv = solv(newGame, gameOverRh,true); if(!resultSolv){ strcpy(message, "No solution"); show_solution=false; } } if (show_solution) { newGame = play_solution(newGame, resultSolv, soluce_move++); } else { if (KEY_MOUSE == ch) { /* Mouse event. */ if (OK == getmouse(&event)) { choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame)); } } else { if (ch == 'q') { quit = true; break; } play_input(newGame, ch, &choosenCar); } } wait_for_size(MINH, MINW); erase_game(newGame, my_win, car, score); draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh); } if (!quit) { display_score(newGame); } for (int i = 0; i < game_nb_pieces(newGame); i++) { destroy_win(car[i]); } destroy_win(my_win); destroy_win(score); free(car); delete_game(newGame); if (resultSolv != NULL) { delete_game(resultSolv->current); free(resultSolv->move); free(resultSolv); resultSolv = NULL; } } endwin(); /* End curses mode */ return 0; }
void clear_tracks(int y, int x) { mvprintw(y, x, aircraft.blank); }
void optimal(const char *requests, int frameSize) { int i, x, y, k, faults, count; char *page, ch, *p; getmaxyx(stdscr, maxy, maxx); werase(stdscr); i = 0; faults = 0; y = (maxy - (frameSize + 3)) / 2; x = (maxx - (strlen(requests)*4 - 1)) / 2; page = (char *)malloc(sizeof(char) * (frameSize + 1)); for(k = 0; k < frameSize; k++) page[k] = 0; page[frameSize - 1] = '\0'; attron(A_BOLD); mvprintw( y - 2, (maxx - 7)/2, "Optimal"); attroff(A_BOLD); while(i < (strlen(requests) - 1)) { i++; ch = requests[i-1]; attron(A_BOLD); mvaddch(y, x + (i - 1)*4, ch); attroff(A_BOLD); if(strchr(page, ch) == NULL) { faults++; if(faults > frameSize) { for(k = i, count = 0; k < (strlen(requests) - 2); k++) { if((strchr(page, requests[k]))!=NULL) count++; else continue; if(count == frameSize) break; } p =strchr(page, requests[k]); *p = ch; rectangle(y + 1, x + (i - 1)*4 + 1, y + frameSize +2, x + i*4 - 1); for(k = 0; k < frameSize; k++) if(page[k]) mvaddch(y+k+2, x + i*4 - 2, page[k]); } else { for(k = 0; k < frameSize; k++) if(page[k] == 0) break; page[k] = ch; } } } attron(A_BOLD); mvprintw( y + frameSize + 4, (maxx - 15)/2, "Page Faults: %d", faults); attroff(A_BOLD); getch(); }
int cw_simulator(void) { extern int simulator; extern int simulator_mode; extern int simulator_seed; extern char simulator_tone[5]; extern char tonestr[5]; extern char tonecpy[5]; extern int system_secs; extern int this_second; static int callnumber; char callcpy[80]; static int x; if (simulator == 0) return (-1); if (simulator_mode == 1) { attron(COLOR_PAIR(C_HEADER) | A_STANDOUT); mvprintw(0, 3, "Sim"); refreshp(); strcpy(tonecpy, tonestr); switch (this_second) { case 48: strcpy(simulator_tone, "625"); break; case 49: strcpy(simulator_tone, "800"); break; case 50: strcpy(simulator_tone, "650"); break; case 51: strcpy(simulator_tone, "750"); break; case 52: strcpy(simulator_tone, "700"); break; case 53: strcpy(simulator_tone, "725"); break; case 54: strcpy(simulator_tone, "675"); break; case 55: strcpy(simulator_tone, "775"); break; case 56: strcpy(simulator_tone, "600"); break; case 57: strcpy(simulator_tone, "640"); break; default: strcpy(simulator_tone, "750"); break; } strcpy(tonestr, simulator_tone); write_tone(); callnumber = callnumber + simulator_seed + system_secs - (60 * (int) (system_secs / 60)); if (callnumber >= 27000) callnumber -= 27000; sendmessage(CALLMASTERARRAY(callnumber)); write_keyer(); simulator_mode = 0; strcpy(tonestr, tonecpy); write_tone(); } if (simulator_mode == 2) { char *str; strcpy(tonecpy, tonestr); strcpy(tonestr, simulator_tone); write_tone(); strcpy(callcpy, CALLMASTERARRAY(callnumber)); x = getctydata(callcpy); str = g_strdup_printf("TU 5NN %2s", zone_export); sendmessage(str); g_free(str); simulator_mode = 0; write_keyer(); strcpy(tonestr, tonecpy); write_tone(); } if (simulator_mode == 3) { char *str; strcpy(tonecpy, tonestr); strcpy(tonestr, simulator_tone); write_tone(); strcpy(callcpy, CALLMASTERARRAY(callnumber)); x = getctydata(callcpy); str = g_strdup_printf("DE %s TU 5NN %s", CALLMASTERARRAY(callnumber), zone_export); sendmessage(str); g_free(str); simulator_mode = 0; write_keyer(); strcpy(tonestr, tonecpy); write_tone(); } return (0); }
static void curses_print_pitch (int pv_pitch) { int oct; int key; if (pv_pitch < 0) { oct = (-pv_pitch - 1) / 12; /* -12 == -2 octaves */ oct = -oct - 1; key = (-pv_pitch - 1) % 12; key = 11 - key; } else { oct = pv_pitch / 12; key = pv_pitch % 12; } switch (key) { case 0: /* 1 degree */ mvprintw (Y_pitch, 1, "pitch : C %+2d (%+3d)", oct, pv_pitch); break; case 1: /* 1.5 */ mvprintw (Y_pitch, 1, "pitch : C# %+2d (%+3d)", oct, pv_pitch); break; case 2: /* +2nd */ mvprintw (Y_pitch, 1, "pitch : D %+2d (%+3d)", oct, pv_pitch); break; case 3: /* 2.5 */ mvprintw (Y_pitch, 1, "pitch : Eb %+2d (%+3d)", oct, pv_pitch); break; case 4: /* +3 */ mvprintw (Y_pitch, 1, "pitch : E %+2d (%+3d)", oct, pv_pitch); break; case 5: /* +4th */ mvprintw (Y_pitch, 1, "pitch : F %+2d (%+3d)", oct, pv_pitch); break; case 6: /* 4.5 */ mvprintw (Y_pitch, 1, "pitch : F# %+2d (%+3d)", oct, pv_pitch); break; case 7: /* +5th */ mvprintw (Y_pitch, 1, "pitch : G %+2d (%+3d)", oct, pv_pitch); break; case 8: /* 5.5 */ mvprintw (Y_pitch, 1, "pitch : G# %+2d (%+3d)", oct, pv_pitch); break; case 9: /* +6th */ mvprintw (Y_pitch, 1, "pitch : A %+2d (%+3d)", oct, pv_pitch); break; case 10: /* m7th */ mvprintw (Y_pitch, 1, "pitch : Bb %+2d (%+3d)", oct, pv_pitch); break; case 11: /* M7 */ mvprintw (Y_pitch, 1, "pitch : B %+2d (%+3d)", oct, pv_pitch); break; default: break; } }
void *background_process(void *ptr) { extern int landebug; extern struct tm *time_ptr; static int i, t; static char prmessage[256]; static int lantimesync = 0; static int fldigi_rpc_cnt = 0; int n; char debugbuffer[160]; FILE *fp; i = 1; while (i) { while (stop_backgrnd_process == 1) { sleep(1); } usleep(10000); if (packetinterface != 0) { receive_packet(); } if (trxmode == DIGIMODE && digikeyer != NO_KEYER) rx_rtty(); /* * calling Fldigi XMLRPC method, which reads the Fldigi's carrier * this function helps to show the correct freq of the RIG: reads * the carrier value from Fldigi, and stores in a variable; then * it readable by fldigi_get_carrier() * only need at every 2nd cycle * see fldigixmlrpc.[ch] */ if (trxmode == DIGIMODE && (digikeyer == GMFSK || digikeyer == FLDIGI) && trx_control == 1) { if (fldigi_rpc_cnt == 0) { fldigi_xmlrpc_get_carrier(); } fldigi_rpc_cnt = 1 - fldigi_rpc_cnt; } if (stop_backgrnd_process == 0) { write_keyer(); cw_simulator(); } if (lan_active == 1) { if (lan_message[0] == '\0') { if (lan_recv() < 0) { recv_error++; } else { lan_message[strlen(lan_message) - 1] = '\0'; } } if (landebug == 1) { if ((fp = fopen("debuglog", "a")) == NULL) { fprintf(stdout, "store_qso.c: Error opening debug file.\n"); } else { get_time(); strftime(debugbuffer, 80, "%H:%M:%S-", time_ptr); if (strlen(lan_message) > 2) { strcat(debugbuffer, lan_message); strcat(debugbuffer, "\n"); fputs(debugbuffer, fp); } fclose(fp); } } if ((*lan_message != '\0') && (lan_message[0] == thisnode)) { mvprintw(24, 0, "Warning: NODE ID CONFLICT ?! You should use another ID! "); refreshp(); sleep(5); } if ((*lan_message != '\0') && (lan_message[0] != thisnode) && (stop_backgrnd_process != 1)) { switch (lan_message[1]) { case LOGENTRY: log_to_disk(true); break; case QTCRENTRY: store_recv_qtc(lan_message+2); break; case QTCSENTRY: store_sent_qtc(lan_message+2); break; case QTCFLAG: parse_qtc_flagline(lan_message+2); break; case CLUSTERMSG: strncpy(prmessage, lan_message + 2, 80); if (strstr(prmessage, call) != NULL) // alert for cluster messages { mvprintw(24, 0, " "); mvprintw(24, 0, "%s", prmessage); refreshp(); } addtext(prmessage); break; case TLFSPOT: strncpy(prmessage, lan_message + 2, 80); lanspotflg = 1; addtext(prmessage); lanspotflg = 0; break; case TLFMSG: for (t = 0; t < 4; t++) strcpy(talkarray[t], talkarray[t + 1]); talkarray[4][0] = lan_message[0]; talkarray[4][1] = ':'; talkarray[4][2] = '\0'; strncat(talkarray[4], lan_message + 2, 60); mvprintw(24, 0, " "); mvprintw(24, 0, " MSG from %s", talkarray[4]); refreshp(); break; case FREQMSG: if ((lan_message[0] >= 'A') && (lan_message[0] <= 'A' + MAXNODES)) { node_frequencies[lan_message[0] - 'A'] = atof(lan_message + 2); break; } case INCQSONUM: n = atoi(lan_message + 2); if (highqsonr < n) highqsonr = n; if ((qsonum <= n) && (n > 0)) { qsonum = highqsonr + 1; qsonr_to_str(); } lan_message[0] = '\0'; case TIMESYNC: if ((lan_message[0] >= 'A') && (lan_message[0] <= 'A' + MAXNODES)) { lantime = atoi(lan_message + 2); if (lantimesync == 1) timecorr = ((4 * timecorr) + lantime - (time(0) + (timeoffset * 3600L))) / 5; else { timecorr = lantime - (time(0) + (timeoffset * 3600L)); lantimesync = 1; } break; } } lan_message[0] = '\0'; lan_message[1] = '\0'; } } gettxinfo(); /* get freq info from TRX */ } return (NULL); }
/* phase vocoder by complex arithmetics with fixed hops. */ void pv_complex_curses (const char * file, long len, long hop_syn) { extern int flag_nofft; int flag_window = 3; struct pv_complex * pv; SNDFILE * sf = NULL; SF_INFO sfinfo; double pv_rate = 1.0; double pv_pitch = 0.0; long frame0 = 0; long frame1; int flag_play = 1; long play_cur = 0; long len_1sec; long len_10sec; ao_device * ao; /* = NULL; */ long status = 1; /* TRUE */ int ch; /* ncurses initializing */ initscr(); /* Start curses mode */ raw(); /* Line buffering disabled */ keypad(stdscr, TRUE); /* We get F1, F2 etc.. */ noecho(); /* Don't echo() while we do getch */ nodelay(stdscr, TRUE); /* Don't wait the key press */ pv = pv_complex_init (len, hop_syn, flag_window); CHECK_MALLOC (pv, "pv_complex_curses"); /* open input file */ memset (&sfinfo, 0, sizeof (sfinfo)); sf = sf_open (file, SFM_READ, &sfinfo); if (sf == NULL) { fprintf (stderr, "fail to open %s", file); exit (1); } /* sndfile_print_info (&sfinfo); */ pv_complex_set_input (pv, sf, &sfinfo); ao = ao_init_16_stereo (sfinfo.samplerate, 0); pv_complex_set_output_ao (pv, ao); /* initial values */ pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); frame1 = (long) pv->sfinfo->frames - 1; pv->flag_lock = 0; /* no phase-lock */ len_1sec = (long) (pv->sfinfo->samplerate /* Hz */); len_10sec = (long) (10 * pv->sfinfo->samplerate /* Hz */); mvprintw (Y_comment, 1, "Welcome WaoN-pv in curses mode. "); curses_print_pv (file, pv, flag_play, frame0, frame1, pv_pitch, pv_rate); /* main loop */ do { if (flag_play != 0) { status = play_100msec_curses (pv, &play_cur, frame0, frame1); } /* scan keyboard */ ch = getch(); switch (ch) { case ERR: /* no key event */ break; case ' ': /* SPACE */ flag_play++; flag_play = flag_play % 2; if (flag_play == 0) mvprintw(Y_status, 1, "status : stop"); else mvprintw(Y_status, 1, "status : play"); break; case '>': case '.': frame1 = play_cur; mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); break; case '<': case ',': frame0 = play_cur; mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); break; case ']': frame1 += len_10sec; if (frame1 >= pv->sfinfo->frames - 1) frame1 = pv->sfinfo->frames - 1; mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); break; case '}': frame1 += len_1sec; if (frame1 >= pv->sfinfo->frames - 1) frame1 = pv->sfinfo->frames - 1; mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); break; case '[': frame0 -= len_10sec; if (frame0 < 0) frame0 = 0; mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); break; case '{': frame0 -= len_1sec; if (frame0 < 0) frame0 = 0; mvprintw (Y_loop, 1, "loop : %010ld - %010ld", frame0, frame1); break; case 'L': case 'l': pv->flag_lock++; pv->flag_lock = pv->flag_lock % 2; if (pv->flag_lock == 0) mvprintw(Y_lock, 1, "phase-lock : off"); else mvprintw(Y_lock, 1, "phase-lock : on "); break; case 'W': case 'w': pv->flag_window++; pv->flag_window = pv->flag_window % 7; /* 0 to 6 */ /* reset scale factor */ pv->window_scale = get_scale_factor_for_window (pv->len, pv->hop_syn, pv->flag_window); curses_print_window (pv->flag_window); break; case 'H': pv->hop_syn *= 2; if (pv->hop_syn > len) pv->hop_syn = len; /* hop_res, hop_ana depend on hop_syn */ pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); break; case 'h': pv->hop_syn /= 2; if (pv->hop_syn < 1) pv->hop_syn = 1; /* hop_res, hop_ana depend on hop_syn */ pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); break; case KEY_UP: pv_pitch += 1.0; pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); curses_print_pitch (pv_pitch); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); break; case KEY_DOWN: pv_pitch -= 1.0; pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); curses_print_pitch (pv_pitch); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); break; case KEY_LEFT: pv_rate -= 0.1; pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); mvprintw (Y_rate, 1, "rate : %-5.1f", pv_rate); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); break; case KEY_RIGHT: pv_rate += 0.1; pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); mvprintw (Y_rate, 1, "rate : %-5.1f", pv_rate); mvprintw (Y_hop_syn, 1, "hop(syn) : %06ld", pv->hop_syn); mvprintw (Y_hop_ana, 1, "hop(ana) : %06ld", pv->hop_ana); mvprintw (Y_hop_res, 1, "hop(res) : %06ld", pv->hop_res); break; case KEY_HOME: case 'R': case 'r': frame0 = 0; frame1 = (long)pv->sfinfo->frames - 1; pv_rate = 1.0; pv_pitch = 0.0; pv->hop_syn = hop_syn; /* value in the argument */ pv_complex_change_rate_pitch (pv, pv_rate, pv_pitch); curses_print_pv (file, pv, flag_play, frame0, frame1, pv_pitch, pv_rate); mvprintw (Y_comment, 1, "reset everything "); break; case 'Q': case 'q': status = 0; mvprintw (Y_comment, 1, "good-bye! "); break; case 'N': case 'n': flag_nofft ++; if (flag_nofft == 2) flag_nofft = 0; if (flag_nofft == 0) mvprintw(Y_lock, 21, " "); else mvprintw(Y_lock, 21, "no-FFT"); break; /* defaut : break; */ } mvprintw (Y_frames, 1, "current : %010ld", play_cur); refresh(); } while (status == 1) ; pv_complex_free (pv); sf_close (sf) ; endwin(); /* End ncurses mode */ }
void print_interface() { int row, col, i; char temp[1024]; char errors[1024]; clear(); row = 1; col = 1; mvprintw(row++, col, " XGV_CCU Help"); mvprintw(row++, col, " w - Wrench Efforts Mode"); mvprintw(row++, col, " m - Motion Profiles Mode"); mvprintw(row++, col, " Up, Down, Left Wright - Throttle and Steering"); mvprintw(row++, col, " SPACE - Maximum Brake, Minimum Throttle, Central Steering"); mvprintw(row++, col, " a, s, d, f - Gear: L, D, N, R"); mvprintw(row++, col, " z, x - Engine: On, Off"); mvprintw(row++, col, " 1, 2, 3, 4 - Turn Signal: Off, Left, Right, Flashes"); mvprintw(row++, col, " 5 - Horn (On/Off)"); mvprintw(row++, col, " 6, 7, 8 - Headlights: Off, Parking lights, On"); mvprintw(row++, col, " 9, 0 - (if Headlight=On) High beams (On/Off), Fog lights (On/Off)"); mvprintw(row++, col, " ESC - Exit XGV_CCU"); row++; mvprintw(row++, col, "g_throttle_command = %lf, g_XGV_throttle = %lf", g_throttle_command, g_XGV_throttle); mvprintw(row++, col, "g_steering_command = %lf, g_XGV_steering = %lf", g_steering_command, g_XGV_steering); mvprintw(row++, col, "g_brakes_command = %lf, g_XGV_brakes = %lf", g_brakes_command, g_XGV_brakes); row++; mvprintw(row++, col, "g_atan_curvature_command = %lf, g_XGV_atan_curvature = %lf", g_atan_curvature_command, g_XGV_atan_curvature); mvprintw(row++, col, "g_velocity_command = %lf, g_XGV_velocity = %lf", g_velocity_command, g_XGV_velocity); mvprintw(row++, col, "Wheels Speed: Front(L,R), Rear(L,R) = (%lf,%lf), (%lf,%lf)", g_XGV_right_front_wheel_speed, g_XGV_left_front_wheel_speed, g_XGV_right_rear_wheel_speed, g_XGV_left_rear_wheel_speed); row++; mvprintw(row++, col, "g_XGV_main_propulsion = %d", g_XGV_main_propulsion); mvprintw(row++, col, "g_XGV_main_fuel_supply = %d", g_XGV_main_fuel_supply); mvprintw(row++, col, "g_XGV_parking_brake = %d", g_XGV_parking_brake); if (g_XGV_gear == 0) mvprintw(row++, col, "g_XGV_gear = P"); if (g_XGV_gear == 1) mvprintw(row++, col, "g_XGV_gear = L"); if ((g_XGV_gear >= 2) && (g_XGV_gear <= 127)) mvprintw(row++, col, "g_XGV_gear = D"); if (g_XGV_gear == 128) mvprintw(row++, col, "g_XGV_gear = N"); if ((g_XGV_gear >= 129) && (g_XGV_gear <= 255)) mvprintw(row++, col, "g_XGV_gear = R"); if (g_XGV_turn_signal == 0) strcpy(temp, "Turn Signal = Off"); else if (g_XGV_turn_signal == 1) strcpy(temp, "Turn Signal = Left"); else if (g_XGV_turn_signal == 2) strcpy(temp, "Turn Signal = Right"); else if (g_XGV_turn_signal == 3) strcpy(temp, "Turn Signal = Flashes"); if (g_XGV_horn_status == 0) strcat(temp, ", Horn = Off"); else if (g_XGV_horn_status == 1) strcat(temp, ", Horn = On"); if ((g_XGV_headlights_status & 7) == 0) strcat(temp, ", Headlights = Off"); else if ((g_XGV_headlights_status & 7) == 1) strcat(temp, ", Parking lights"); else if ((g_XGV_headlights_status & 7) == 2) { strcat(temp, ", Headlights = On"); if (g_XGV_headlights_status & 8) strcat(temp, ", High beans = On"); if (g_XGV_headlights_status & 0x10) strcat(temp, ", Fog lights = On"); } mvprintw(row++, col, "%s", temp); get_errors_descriptions(); row++; if (g_XGV_num_errors == 0) strcpy(errors, ""); else if (g_XGV_num_errors == 1) { sprintf(errors, ", error: (%d) %s", g_error_description[g_error[0]].error_code, g_error_description[g_error[0]].error_description); } else { strcpy(errors, ", errors:"); for (i = 0; i < g_XGV_num_errors; i++) sprintf(errors + strlen(errors), " (%d) %s ", g_error_description[g_error[i]].error_code, g_error_description[g_error[i]].error_description); } switch (g_control_mode) { case SOFTWARE_PAUSE_MODE: mvprintw(row++, col, "mode: SOFTWARE_PAUSE_MODE%s", errors); break; case WRENCH_EFFORTS_MODE: mvprintw(row++, col, "mode: WRENCH_EFFORTS_MODE%s", errors); break; case MOTION_PROFILES_MODE: mvprintw(row++, col, "mode: MOTION_PROFILES_MODE%s", errors); break; } //move(0,0); refresh(); }
void browse_draw() { struct dir *t; char fmtsize[9], *tmp; int selected = 0, i; erase(); t = dirlist_get(0); /* top line - basic info */ attron(A_REVERSE); mvhline(0, 0, ' ', wincols); mvhline(winrows-1, 0, ' ', wincols); mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ? for help", PACKAGE_NAME, PACKAGE_VERSION); if(dir_import_active) mvaddstr(0, wincols-10, "[imported]"); else if(read_only) mvaddstr(0, wincols-11, "[read-only]"); attroff(A_REVERSE); /* second line - the path */ mvhline(1, 0, '-', wincols); if(t) { mvaddch(1, 3, ' '); tmp = getpath(t->parent); mvaddstr(1, 4, cropstr(tmp, wincols-8)); mvaddch(1, 4+((int)strlen(tmp) > wincols-8 ? wincols-8 : (int)strlen(tmp)), ' '); } /* bottom line - stats */ attron(A_REVERSE); if(t) { strcpy(fmtsize, formatsize(t->parent->size)); mvprintw(winrows-1, 0, " Total disk usage: %s Apparent size: %s Items: %d", fmtsize, formatsize(t->parent->asize), t->parent->items); } else mvaddstr(winrows-1, 0, " No items to display."); attroff(A_REVERSE); /* nothing to display? stop here. */ if(!t) return; /* get start position */ t = dirlist_top(0); /* print the list to the screen */ for(i=0; t && i<winrows-3; t=dirlist_next(t),i++) { browse_draw_item(t, 2+i); /* save the selected row number for later */ if(t->flags & FF_BSEL) selected = i; } /* draw message window */ if(message) { nccreate(6, 60, "Message"); ncaddstr(2, 2, message); ncaddstr(4, 34, "Press any key to continue"); } /* draw information window */ t = dirlist_get(0); if(!message && info_show && t != dirlist_parent) browse_draw_info(t); /* move cursor to selected row for accessibility */ move(selected+2, 0); }
/* Display the game state on the terminal. The map is placed in the * upper left corner, and the status information goes in the upper * right corner. */ int displaygame(cell const *map, int ysize, int xsize, int recording, int macro, int save, char const *seriesname, char const *levelname, int index, int boxcount, int storecount, int movecount, int pushcount, int bestmovecount, int bestpushcount) { cell const *p; char buf[SIDEBARWIDTH + 1]; int y, x, n; erase(); if (ysize > fieldheight || xsize > fieldwidth) { mvprintw(0, 0, "Level %d won't fit on the screen.", index); refresh(); return FALSE; } p = map; for (y = 1, p += XSIZE ; y < ysize - 1 ; ++y, p += XSIZE) { if (y != 1) addch('\n'); for (x = 1 ; x < xsize - 1 ; ++x) { addch(screencells[p[x] & 0x0F][0]); addch(screencells[p[x] & 0x0F][1]); } } sprintf(buf, "# %d", index); mvprintw(0, sidebar, "%*s", SIDEBARWIDTH, buf); mvprintw(1, sidebar, " Boxes: %-3d %c", boxcount, recording ? 'R' : macro ? 'M' : ' '); mvprintw(2, sidebar, "Stored: %-3d %c", storecount, save ? 'S' : ' '); mvprintw(3, sidebar, " Moves: %d", movecount); mvprintw(4, sidebar, "Pushes: %d", pushcount); if (bestmovecount && bestpushcount) { mvprintw(5, sidebar, " Best: %d", bestmovecount); if (bestmovecount < 100000) addstr(" moves"); if (bestpushcount < 10000) mvprintw(6, sidebar + 8, "%d pushes", bestpushcount); else mvprintw(6, sidebar + 4, "%7d pushes", bestpushcount); } y = 8; if (seriesname) { for (n = 0 ; seriesname[n] && y <= lastline ; ++y) { move(y, sidebar); n = lineout(seriesname, n); } ++y; } if (levelname) { for (n = 0 ; levelname[n] && y <= lastline ; ++y) { move(y, sidebar); n = lineout(levelname, n); } } move(lastline, sidebar + SIDEBARWIDTH - 1); refresh(); return TRUE; }
void labelkre(void) { int i, j, l; mvprintw(MEMROW, MEMCOL, " memory totals (in KB)"); mvprintw(MEMROW + 1, MEMCOL, " real virtual free"); mvprintw(MEMROW + 2, MEMCOL, "Active"); mvprintw(MEMROW + 3, MEMCOL, "All"); mvprintw(PAGEROW, PAGECOL, " PAGING SWAPPING "); mvprintw(PAGEROW + 1, PAGECOL, " in out in out "); mvprintw(PAGEROW + 2, PAGECOL, "ops"); mvprintw(PAGEROW + 3, PAGECOL, "pages"); mvprintw(INTSROW, INTSCOL + 3, " Interrupts"); mvprintw(INTSROW + 1, INTSCOL + 9, "total"); mvprintw(LINES - 3, INTSCOL + 9, "IPKTS"); mvprintw(LINES - 2, INTSCOL + 9, "OPKTS"); mvprintw(VMSTATROW + 0, VMSTATCOL + 10, "forks"); mvprintw(VMSTATROW + 1, VMSTATCOL + 10, "fkppw"); mvprintw(VMSTATROW + 2, VMSTATCOL + 10, "fksvm"); mvprintw(VMSTATROW + 3, VMSTATCOL + 10, "pwait"); mvprintw(VMSTATROW + 4, VMSTATCOL + 10, "relck"); mvprintw(VMSTATROW + 5, VMSTATCOL + 10, "rlkok"); mvprintw(VMSTATROW + 6, VMSTATCOL + 10, "noram"); mvprintw(VMSTATROW + 7, VMSTATCOL + 10, "ndcpy"); mvprintw(VMSTATROW + 8, VMSTATCOL + 10, "fltcp"); mvprintw(VMSTATROW + 9, VMSTATCOL + 10, "zfod"); mvprintw(VMSTATROW + 10, VMSTATCOL + 10, "cow"); mvprintw(VMSTATROW + 11, VMSTATCOL + 10, "fmin"); mvprintw(VMSTATROW + 12, VMSTATCOL + 10, "ftarg"); mvprintw(VMSTATROW + 13, VMSTATCOL + 10, "itarg"); mvprintw(VMSTATROW + 14, VMSTATCOL + 10, "wired"); mvprintw(VMSTATROW + 15, VMSTATCOL + 10, "pdfre"); if (LINES - 1 > VMSTATROW + 16) mvprintw(VMSTATROW + 16, VMSTATCOL + 10, "pdscn"); if (LINES - 1 > VMSTATROW + 17) mvprintw(VMSTATROW + 17, VMSTATCOL + 10, "pzidle"); if (LINES - 1 > VMSTATROW + 18) mvprintw(VMSTATROW + 18, VMSTATCOL + 10, "kmapent"); mvprintw(GENSTATROW, GENSTATCOL, " Csw Trp Sys Int Sof Flt"); mvprintw(GRAPHROW, GRAPHCOL, " . %%Int . %%Sys . %%Usr . %%Nic . %%Idle"); mvprintw(PROCSROW, PROCSCOL, "Proc:r d s w"); mvprintw(GRAPHROW + 1, GRAPHCOL, "| | | | | | | | | | |"); mvprintw(NAMEIROW, NAMEICOL, "Namei Sys-cache Proc-cache No-cache"); mvprintw(NAMEIROW + 1, NAMEICOL, " Calls hits %% hits %% miss %%"); mvprintw(DISKROW, DISKCOL, "Disks"); mvprintw(DISKROW + 1, DISKCOL, "seeks"); mvprintw(DISKROW + 2, DISKCOL, "xfers"); mvprintw(DISKROW + 3, DISKCOL, "speed"); mvprintw(DISKROW + 4, DISKCOL, " sec"); for (i = 0, j = 0; i < cur.dk_ndrive && j < DRIVESPACE; i++) if (cur.dk_select[i] && (j + strlen(dr_name[i])) < DRIVESPACE) { l = MAX(5, strlen(dr_name[i])); mvprintw(DISKROW, DISKCOL + 5 + j, " %*s", l, dr_name[i]); j += 1 + l; } for (i = 0; i < nintr; i++) { if (intrloc[i] == 0) continue; mvprintw(intrloc[i], INTSCOL + 9, "%-8.8s", intrname[i]); } }
/* Main execution loop in live mode. Builds the list of processes, * collects statistics, and prints using curses. Repeats after some * delay, also catching key presses. */ static int live_mode(struct process_list* proc_list, screen_t* screen) { WINDOW* help_win = NULL; WINDOW* error_win = NULL; fd_set fds; struct process** p; int num_iter = 0; int with_colors = 0; int pos; /* start curses */ initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); /* Prepare help window */ help_win = prepare_help_win(screen); if (has_colors()) { /* initialize curses colors */ with_colors = 1; start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_WHITE, COLOR_BLACK); init_pair(3, COLOR_GREEN, COLOR_BLACK); init_pair(4, COLOR_YELLOW, COLOR_BLACK); init_pair(5, COLOR_RED, COLOR_BLACK); attron(COLOR_PAIR(0)); } tv.tv_sec = 0; tv.tv_usec = 200000; /* 200 ms for first iteration */ header = gen_header(screen, &options, COLS - 1, active_col); pos = screen_pos(screen); for(num_iter=0; !options.max_iter || num_iter<options.max_iter; num_iter++) { int i, zz, printed, num_fd, num_dead; /* print various info */ erase(); mvprintw(0, 0, "tiptop -"); if ((num_errors() > 0) && (COLS >= 37)) mvprintw(LINES-1, 30, "[errors]"); if ((options.config_file == 1) && (COLS >= 60)) mvprintw(0, COLS-60, "[conf]"); if ((options.euid == 0) && (COLS >= 54)) mvprintw(0, COLS-54, "[root]"); if ((options.watch_uid != -1) && (COLS >= 48)) mvprintw(0, COLS-48, "[uid]"); if ((options.only_pid || options.only_name) && (COLS >= 43)) mvprintw(0, COLS-43, "[pid]"); if (options.show_kernel && (COLS >= 38)) mvprintw(0, COLS-38, "[kernel]"); if (options.sticky && (COLS >= 30)) mvprintw(0, COLS-30, "[sticky]"); if (options.show_threads && (COLS >= 22)) mvprintw(0, COLS-22, "[threads]"); if (options.idle && (COLS >= 13)) mvprintw(0, COLS-13, "[idle]"); if (options.debug && (COLS >= 7)) mvprintw(0, COLS-7, "[debug]"); if (options.show_epoch && (COLS >= 18)) mvprintw(LINES-1, COLS-18, "Epoch: %u", time(NULL)); if (options.show_timestamp) mvprintw(LINES-1, 0, "Iteration: %u", num_iter); /* print main header */ if (with_colors) attron(COLOR_PAIR(1)); mvprintw(3, 0, "%s", header); for(zz=strlen(header); zz < COLS-1; zz++) printw(" "); printw("\n"); if (with_colors) attroff(COLOR_PAIR(1)); /* update the list of processes/threads and accumulate info if needed */ num_dead = update_proc_list(proc_list, screen, &options); if (!options.show_threads) accumulate_stats(proc_list); p = proc_list->proc_ptrs; /* prepare for select */ FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); /* generate the text version of all rows */ build_rows(proc_list, screen, COLS - 1); /* sort by %CPU */ qsort(p, proc_list->num_tids, sizeof(struct process*), sorting_fun); printed = 0; /* Iterate over all threads */ for(i=0; i < proc_list->num_tids; i++) { if (p[i]->skip) continue; /* highlight watched process, if any */ if (with_colors) { if (p[i]->dead) { attron(COLOR_PAIR(5)); } else if ((p[i]->tid == options.watch_pid) || (options.watch_name && options.show_cmdline && strstr(p[i]->cmdline, options.watch_name)) || (options.watch_name && !options.show_cmdline && strstr(p[i]->name, options.watch_name))) attron(COLOR_PAIR(3)); } if (options.show_threads || (p[i]->pid == p[i]->tid)) { printw("%s\n", p[i]->txt); printed++; } if (with_colors) attroff(COLOR_PAIR(3)); if (printed >= LINES - 5) /* stop printing at bottom of window */ break; } mvprintw(1, 0, "Tasks: %3d total, %3d displayed", proc_list->num_tids, printed); if (options.sticky) printw(", %3d dead", num_dead); /* print the screen name, make sure it fits, or truncate */ if (with_colors) attron(COLOR_PAIR(4)); if (35 + 20 + 11 + strlen(screen->name) < COLS) { mvprintw(1, COLS - 11 - strlen(screen->name), "screen %2d: %s\n", pos, screen->name); } else if (COLS >= 35 + 20 + 11) { char screen_str[50] = { 0 }; snprintf(screen_str, sizeof(screen_str) - 1, "%s\n", screen->name); screen_str[COLS - 35 - 20 - 11] = '\0'; /* truncate */ mvprintw(1, 35+20, "screen %2d: %s", pos, screen_str); } if (with_colors) attroff(COLOR_PAIR(4)); /* print message if any */ if (message) { if (with_colors) attron(COLOR_PAIR(1)); mvprintw(2, 0, "%s", message); if (with_colors) attroff(COLOR_PAIR(1)); message = NULL; /* reset message */ } refresh(); /* display everything */ if (options.error) { if (options.error == 1) { options.error = 2; show_error_win(error_win, printed); } else show_error_win(error_win, -1); } if (options.help) show_help_win(help_win, screen); if ((num_dead) && (!options.sticky)) compact_proc_list(proc_list); /* wait some delay, or until a key is pressed */ num_fd = select(1 + STDIN_FILENO, &fds, NULL, NULL, &tv); if (num_fd > 0) { int c = handle_key(); if (c == 'q') break; if (c == '>') { if (active_col < screen->num_columns ) active_col++; free(header); header = gen_header(screen, &options, COLS - 1, active_col); } if (c == '<') { if (active_col > -1) active_col--; free(header); header = gen_header(screen, &options, COLS - 1, active_col); } if (c == 'H') { if (options.show_threads) { reset_values(proc_list); message = "Show threads On"; } else message = "Show threads Off"; } if (c == 'U') { free(header); header = gen_header(screen, &options, COLS - 1, active_col); } if ((c == '+') || (c == '-') || (c == KEY_LEFT) || (c == KEY_RIGHT)) return c; if ((c == 'u') || (c == 'K') || (c == 'p')) /* need to rebuild tasks list */ return c; if (c == 'e') { if (options.error > 0) { options.error = 0; delwin(error_win); error_win = NULL; } else options.error = 1; } } tv.tv_sec = options.delay; tv.tv_usec = (options.delay - tv.tv_sec) * 1000000.0; } free(header); delwin(help_win); endwin(); /* stop curses */ return 'q'; }