/* * Take a finite amount of results and show them full-screen. * * If the number of results is greater than the available lines on screen, * display a prompt to refine the keywords. */ void _pager(bool start_with_prompt) { init_curses(); for (;;) { clear(); if (start_with_prompt) { start_with_prompt = false; keyword_prompt(); filter_results(); continue; } refresh_listing(); /* Wait for any keystroke, a slash or a timeout. */ if (getch() == '/') { keyword_prompt(); filter_results(); continue; } break; } shutdown_curses(); }
int main( int argc, char *argv[] ) { WINDOW *win; init_curses(); box(stdscr, ACS_VLINE, ACS_HLINE ); mvaddstr( LINES / 2 - 5, COLS / 2 - 5, "hello world" ); refresh(); sleep(1); win = newwin(4, 30, LINES / 2 - 3, COLS / 2 - 15 ); box(win, ACS_VLINE, ACS_HLINE ); mvwaddstr( win, 1, 2, "hello world!!!" ); touchwin(win); wrefresh(win); getch(); wclear(win); touchwin(stdscr); sleep(5); endwin(); return 0; }
int userinit() { install_null(); /* install device /dev/null or NUL: */ init_curses(); return 0; }
/* See interface.h for function descriptions. */ int if_init(void) { if (init_curses()) return 1; hl_groups_instance = hl_groups_initialize(); if (!hl_groups_instance) return 3; if (hl_groups_setup(hl_groups_instance) == -1) return 3; /* Set up the signal handler to catch SIGWINCH */ if (set_up_signal() == -1) return 2; if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) { screen_size.ws_row = LINES; screen_size.ws_col = COLS; } /* Create the file dialog object */ if ((fd = filedlg_new(0, 0, HEIGHT, WIDTH)) == NULL) return 5; /* Set up window layout */ window_height_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0)); switch (if_layout()) { case 2: return 4; } return 0; }
int main(void){ square **map; int pause = 0; int c; //initialize init_curses(); map = allocate_map(); //Glider /* map[5][5].cur = LIVE; map[5][6].cur = LIVE; map[5][7].cur = LIVE; map[4][7].cur = LIVE; map[3][6].cur = LIVE; */ //Ocilator /* map[5][5].cur = LIVE; map[6][5].cur = LIVE; map[7][5].cur = LIVE; */ for(;;){ if((c = kbhit()) != 0){ switch(c){ case 32: if(pause == 0) pause = 1; else if(pause == 1) pause = 0; break; case 27: destruct(map); return 0; case 100: pause = 1; drawMode(map); break; case 112: writeFile(map); break; case 114: readFile(map); pause = 1; break; case 99: clearScr(map); draw(map, 0); pause = 1; break; } } if(pause == 0) gameoflife(map); usleep(SECOND/FPS); } destruct(map); return 0; }
void main(){ init_curses(); init_colors(); while (1){ level_editor(); } }
int main() { init_curses(); const char *exit_msg = ""; srandom(time(NULL)); struct game_t game = {0}; int last_turn = game.turns; get_highscore_filepath(&game); load_highscore(&game); place_tile(&game); place_tile(&game); while (1) { print_game(&game); if (lose_game(game)) { exit_msg = "lost"; goto lose; } last_turn = game.turns; switch (getch()) { case 'h': case KEY_LEFT: case 'a': move_left(&game); break; case 'j': case KEY_DOWN: case 's': move_down(&game); break; case 'k': case KEY_UP: case 'w': move_up(&game); break; case 'l': case KEY_RIGHT: case 'd': move_right(&game);break; case 'q': exit_msg = "quit"; goto end; } if (last_turn != game.turns) place_tile(&game); } lose: move(7, 0); printw("You lose! Press q to quit."); while (getch() != 'q'); end: endwin(); if(game.score > game.highscore) { game.highscore = game.score; save_highscore(&game); } printf("You %s after scoring %d points in %d turns, " "with largest tile %d. The local highscore is %d points.\n", exit_msg, game.score, game.turns, 1 << max_tile((tile_t *)game.board), game.highscore); free(game.highscorefile); return 0; }
void init_ui(char *name) { init_curses(); init_tree(name); init_lines(); print_line(FILE(tree_root)->line); open_directory(tree_root); refresh_screen(); }
int main(int argc, char** argv) { if (argc != 3 && argc != 4) { fprintf(stderr, "%s\n", usage); exit(EXIT_FAILURE); } basic_input = false; if (argc == 4 && strcmp(argv[3], "--stdin") == 0) { basic_input = true; } else if (argc == 4) { //Gave invalid final argument fprintf(stderr, "Invalid arg: '%s'\n%s", argv[3], usage); exit(EXIT_FAILURE); } int server_socket = -1; int error = -1; char* host = argv[1]; char* port = argv[2]; init_curses(basic_input); //Init window for ncurses interface draw_msgs(); //Draw empty chat window server_socket = connect_to_server(host, port); if (server_socket < 0) { endwin(); printf("Error connecting to server %s on socket %s\n", host, port); exit(EXIT_FAILURE); } if ((LOG_FD = open(LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, S_IRWXU)) < 0) { printf("Error opening log file: %s\n", strerror(errno)); } error = pthread_create(&(receive_thread), NULL, (void*(*)(void*)) receive_loop, (void*) &server_socket); if (error != 0) { endwin(); pthread_cancel(receive_thread); printf("Error creating pthread. Exiting program.\n"); exit(EXIT_FAILURE); } command_loop(server_socket); pthread_cancel(receive_thread); endwin(); //Shouldn't ever reach this code. But, close window if this happens. return 0; }
/** * Main loop of the function. */ int main(int argc, char *argv[]) { int ch, prev; prev = EOF; FILE *fp = NULL; int y, x; if (argc != 2) { printf("Usage: %s <file.c>\n", argv[0]); exit(1); } char f_flag = 'r'; fp = fopen(argv[1], &f_flag); if (fp == NULL) { perror("Cannot open input file."); exit(1); } init_curses(); while ((ch = fgetc(fp)) != EOF) { getyx(stdscr, y, x); if (y == (LINES - 1)) { /* Got to last line, clear and keep printing. */ printw("<- Press any key->"); getch(); clear(); /* Clear screen */ move(0, 0); } if (prev == '/' && ch == '*') { attron(A_BOLD); getyx(stdscr, y, x); move(y, x-1); printw("%c%c", prev, ch); } else { printw("%c", ch); } refresh(); if (prev == '*' && ch == '/') attroff(A_BOLD); prev = ch; } getch(); endwin(); if (fp != NULL) fclose(fp); return 0; }
/***************************** main function *****************************/ int main(int argc, char **argv) { struct map *map; int x0, y0, x1, y1; /* parse args */ if (argc < 6) { fprintf(stderr, "%s needs at least 5 arguments (%d were given)\n", PROGRAM_NAME, argc-1); fprintf(stderr, "usage: %s mapfile x0 y0 x1 y1 (time_interval - optional)\n", PROGRAM_NAME); exit(EXIT_FAILURE); } x0 = atoi(argv[2]); y0 = atoi(argv[3]); x1 = atoi(argv[4]); y1 = atoi(argv[5]); g_curses_interval = 0; if (argc > 6) { g_curses_interval = atoi(argv[6]); } map = load_map(argv[1]); if (!map) { fprintf(stderr, "Error loading map.\n"); exit(EXIT_FAILURE); } if ((x0 <= 0 || x0 >= map->width-1) || (x1 <= 0 || x1 >= map->width-1) || (y0 <= 0 || y0 >= map->height-1) || (y1 <= 0 || y1 >= map->height-1)) { fprintf(stderr, "Coordinates are not in range.\n"); exit(EXIT_FAILURE); } /* initialise the curses animation if we're using that */ if (g_curses_interval > 0) { init_curses(); } make_path(map, x0, y0, x1, y1); if (g_curses_interval > 0) { end_curses(); } else { print_path(map, x0, y0, x1, y1); } map_destroy(map); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { char *dev, errbuf[PCAP_ERRBUF_SIZE]; pcap_t *handle; int selectable_fd; if (argc == 2) { dev = argv[1]; } else { dev = pcap_lookupdev(errbuf); } if (dev == NULL) { fprintf(stderr, "Couldn't find default device: %s\n", errbuf); return (2); } handle = pcap_open_live(dev, BUFSIZ, 1, 0, errbuf); if (handle == NULL) { fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf); return (2); } if (pcap_datalink(handle) != DLT_EN10MB) { fprintf(stderr, "Device %s doesn't provide Ethernet headers - " "not supported\n", dev); return (2); } if (pcap_setnonblock(handle, 1, errbuf) != 0) { fprintf(stderr, "Non-blocking mode failed: %s\n", errbuf); return (2); } selectable_fd = pcap_get_selectable_fd(handle); if (-1 == selectable_fd) { fprintf(stderr, "pcap handle not selectable.\n"); return (2); } init_curses(); mvprintw(0, 0, "Device: %s\n", dev); grab_packets(selectable_fd, handle); /* And close the session */ pcap_close(handle); return 0; }
int main() { init_curses(); const char *exit_msg = ""; srand(time(NULL)); struct game_t game = {0}; int last_turn = game.turns; place_tile(&game); place_tile(&game); while (1) { print_game(&game); if (lose_game(game)) { exit_msg = "lost"; goto lose; } last_turn = game.turns; switch (getch()) { case 'h': case KEY_LEFT: move_left(&game); break; case 'j': case KEY_DOWN: move_down(&game); break; case 'k': case KEY_UP: move_up(&game); break; case 'l': case KEY_RIGHT: move_right(&game); break; case 'q': exit_msg = "quit"; goto end; } if (last_turn != game.turns) place_tile(&game); } lose: move(7, 0); printw("You lose! Press q to quit."); while (getch() != 'q'); end: endwin(); printf("You %s after scoring %d points in %d turns, " "with largest tile %d\n", exit_msg, game.score, game.turns, 1 << max_tile((tile_t *)game.board)); return 0; }
void main_curses(World_t* world, unsigned long long int sleep_time) { // Initialize the `last_time` variable for the real-time clock. Tracks the // time the last loop began for calculating time to wait. unsigned long long last_time = 0; int playing = 1; // Is the simulation "playing" or "paused"? int running = 1; // Should the simulation continue to run? int current_char; // What is the current keyboard input? // Initialize frontend WINDOW* window = init_curses(); Lens_t lens; lens_init(&lens, world->board, 132, 43, false); // Display game board, find next generation, wait for time and loop while(running) { current_char = getch(); if (current_char == 27 || current_char == 'q') { running = 0; } if (current_char == 'p') { playing = 0; } if (current_char == 'r') { playing = 1; } if (current_char == 'h' || current_char == KEY_LEFT) { lens_move_left(&lens); } if (current_char == 'j' || current_char == KEY_DOWN) { lens_move_down(&lens); } if (current_char == 'k' || current_char == KEY_UP) { lens_move_up(&lens); } if (current_char == 'l' || current_char == KEY_RIGHT) { lens_move_right(&lens); } if (playing) { display_curses(world, &lens, window); generate(world); wait(sleep_time, &last_time); } } // Destroy curses endwin(); }
int main(void){ init_curses(); // blue_disp(); // getch(); //ボタン入力待ち // red_disp(); // disp_tile_row( 3, 5, 5); // disp_tile_row( 3, 5, 7); getch(); //ボタン入力待ち end_curses(); return 0; }
/* See interface.h for function descriptions. */ int if_init(void) { if (init_curses()) { clog_error(CLOG_CGDB, "Unable to initialize the ncurses library"); return -1; } hl_groups_instance = hl_groups_initialize(); if (!hl_groups_instance) { clog_error(CLOG_CGDB, "Unable to setup highlighting groups"); return -1; } if (hl_groups_setup(hl_groups_instance) == -1) { clog_error(CLOG_CGDB, "Unable to setup highlighting groups"); return -1; } /* Set up the signal handler to catch SIGWINCH */ if (set_up_signal() == -1) { clog_error(CLOG_CGDB, "Unable to handle signal: SIGWINCH"); return -1; } if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) { screen_size.ws_row = swin_lines(); screen_size.ws_col = swin_cols(); } /* Create the file dialog object */ fd = filedlg_new(0, 0, HEIGHT, WIDTH); /* Set up window layout */ window_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0)); switch (if_layout()) { case 2: return 4; } G_line_number = ibuf_init(); return 0; }
void Vga_init ( struct vga_t *x, int cpuid, bit32u_t pmem_base ) { ASSERT ( x != NULL ); x->fd = Open2_fmt ( O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, "/tmp/vga%d", cpuid ); x->base_y = 0; #ifdef ENABLE_CURSES init_curses ( ); print_menu ( ); x->subwin = create_subwin ( ); #endif }
Program::Program(int argc, char** argv) { program = this; basepath = dir(realpath(argv[0])); userpath = {nall::configpath(), "termboy/"}; sharedpath = {nall::sharedpath(), "termboy/"}; directory::create(userpath); bootstrap(); active = nullptr; config = new ConfigurationSettings; utility = new Utility; audio.driver("ALSA"); if(audio.init() == false) { audio.driver("None"); audio.init(); } init_curses(); inputManager = new InputManager(); inputManager->setupKeyboard(); dspaudio.setPrecision(16); dspaudio.setBalance(0.0); dspaudio.setFrequency(96000); utility->synchronizeRuby(); utility->updateShader(); if(argc >= 2) utility->loadMedia(argv[1]); //TODO: This is bad! Remove hardcoded string and use appropriate path //TODO: periodically sync RAM in case of crash? Ananke ananke; ananke.sync("/home/dobyrch/ROMs/Game Boy/pokemon_blue.gb"); while(true) { main(); } utility->unload(); //config->save(); }
int main(int argc, char *argv[]) { int serverport; char *serveraddr; if (argc >= 3) { serveraddr = argv[1]; serverport = atoi(argv[2]); } else { puts("Usage: ping [server] [port]"); exit(0); } unsigned int seed = time(NULL); srandom(seed); SLEEPT = 125000; user1_serving = 1; user1_serving_now = 1; user_served = 0; init_curses(); init_game(); netset(serverport, serveraddr); redraw(); serve(); while (!end) { redraw(); userctl(getch()); peersync(); move_ball(); redraw(); usleep(SLEEPT); } end_curses(); return 0; }
main() { int k; init_world(); init_curses(); draw_vmap(); // fskipc=0; do { //Keyboard loop if(pause==0) { evolv(); //k=fskipc/fskip; if ((fskipc%fskip)==0) { //fskipc=0; info_status(); draw_vmap(); } fskipc++; age++; } cho=getch(); } while(kbd()); finish_game(); return(0); }
int main (void) { int tab[DIM_JEU][DIM_JEU], key, int_jeu_2048, score=0; char continuer='y'; srand(time(NULL)); init_curses(); bkgd(COLOR_PAIR(1)); affiche_menu(); key=getch(); while(key!=ESCAPE) { if(key == KEY_F(2)) { clear(); affiche_menu(); InitJeu(tab, &score); do { int_jeu_2048 = jeu_2048(tab, &score); if(int_jeu_2048 == 3) { move(4,0); printw(" Vous avez atteint l'objectif ! \n"); printw(" Vous voulez continuer? (y/n) "); continuer = SaisieOuiNon(); } } while (continuer == 'y' && int_jeu_2048 > 1); if(int_jeu_2048 == 0) printw(" Vouz avez perdu. \n"); if(int_jeu_2048 == 1) printw(" Vouz ne pouvez plus retasser. \n"); } key=getch(); } endwin(); return 0; }
void change_screen_size (void) { #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 #if defined TIOCGWINSZ && !defined SCO_FLAVOR extern Dlg_head *view_dlg; extern Dlg_head *edit_dlg; #ifndef NCURSES_VERSION mc_noraw_mode (); endwin (); #endif low_level_change_screen_size (); check_split (); #ifndef NCURSES_VERSION /* XSI Curses spec states that portable applications shall not invoke * initscr() more than once. This kludge could be done within the scope * of the specification by using endwin followed by a refresh (in fact, * more than one curses implementation does this); it is guaranteed to work * only with slang. */ init_curses (); #endif setup_panels (); if (current_dlg == view_dlg) view_adjust_size (view_dlg); #ifdef USE_INTERNAL_EDIT if (current_dlg == edit_dlg) edit_adjust_size (edit_dlg); #endif #ifdef RESIZABLE_MENUBAR menubar_arrange(the_menubar); #endif /* Now, force the redraw */ do_refresh (); touchwin (stdscr); #endif /* TIOCGWINSZ && !SCO_FLAVOR */ #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */ winch_flag = 0; }
void display_field(char** field, int n, int m) { WINDOW* display_window; int displayn, displaym, ch, row, column, maxn, maxm; init_curses(); maxn = LINES - 8; maxm = COLS - 10; print_message_center(stdscr, 2, "Use arrow keys to move among field"); print_message_center(stdscr, 4, "Press ESC to exit"); displayn = min(maxn, n); displaym = min(maxm, m); refresh(); display_window = newwin(displayn + 2, displaym + 2, (LINES - displayn - 2 - 4) / 2 + 5, (COLS - displaym - 2) / 2); box(display_window, 0, 0); wrefresh(display_window); synchronize_window_with_field(display_window, field, n, m, 0, 0); row = column = 0; do { ch = getch(); switch(ch) { case KEY_UP: row = normalize_koordinate(row - 1, n); break; case KEY_DOWN: row = normalize_koordinate(row + 1, n); break; case KEY_LEFT: column = normalize_koordinate(column - 1, m); break; case KEY_RIGHT: column = normalize_koordinate(column + 1, m); break; } synchronize_window_with_field(display_window, field, n, m, row, column); } while (ch != 27); clear(); endwin(); }
int main(int argc, char** argv) { pthread_t t1; const char* m1 = "thread1"; pthread_mutex_init(&mutex, NULL); int row = 28, col = 37; init_curses(); printw("Welcome to Space Invaders.\nPlease select your difficulty:\n(h)ard\n(n)ormal\n(e)asy\nTo quit press \'q\'"); int ch = getch(); clear(); set_difficulty(ch); pthread_create(&t1, 0, badguy_fn, (void*)m1); game_loop(row, col, ch); game_over(); return 0; }
int main() { char key; largeur=21; hauteur=7; tableau = (int*) malloc(largeur*hauteur*sizeof(int)); vaisseau=')';// D)]#->??* load_highscore(); init_curses(); srand((unsigned int) time(NULL)); anim_debut(); help(); /* Boucle principale, menu */ do { key=wgetch(menubar); switch(key) { case 'n': partie(); break; case 's': view_highscores(); break; case 'a': help(); break; case 'q': end_curses(); return 0; } } while (1); }
int main(int argc, const char *argv[]) { int x_max,y_max; init_curses(); draw_bottom(); #ifdef debug fprintf(moon_log,"hello yaomoon\n"); #endif fill_state(); display_win(&state); fill_error(); display_win(&error); //wprintw(state.win,"%s %s\n","name","yaomoon"); //wrefresh(state.win); while(1); endwin(); return 0; }
/* * Take a finite amount of results and show them full-screen. * * If the number of results is greater than the available lines on screen, * display a prompt to refine the keywords. */ int pager() { init_curses(); while (1) { clear(); refresh_listing(); /* Wait for any keystroke, a slash or a timeout. */ if (getch() == '/') { keyword_prompt(); filter_results(); continue; } break; } shutdown_curses(); return MODE_EXIT; }
void change_screen_size (void) { #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 #if defined TIOCGWINSZ #ifndef NCURSES_VERSION mc_noraw_mode (); endwin (); #endif low_level_change_screen_size (); check_split (); #ifndef NCURSES_VERSION /* XSI Curses spec states that portable applications shall not invoke * initscr() more than once. This kludge could be done within the scope * of the specification by using endwin followed by a refresh (in fact, * more than one curses implementation does this); it is guaranteed to work * only with slang. */ init_curses (); #endif setup_panels (); /* Inform currently running dialog */ (*current_dlg->callback) (current_dlg, DLG_RESIZE, 0); #ifdef RESIZABLE_MENUBAR menubar_arrange (the_menubar); #endif /* Now, force the redraw */ do_refresh (); touchwin (stdscr); #endif /* TIOCGWINSZ */ #endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */ winch_flag = 0; }
int main() { if (oamlInitAudioDevice(44100, 2) != OAML_OK) { fprintf(stderr, "Unable to open audio device!\n"); exit(1); } oamlInit("oaml.defs"); // for some better random numbers (and not always the same) srand(time(NULL)); init_curses(); main_menu(); oamlShutdown(); end_curses(); // free the allocated memory for the highscore read_highscore(NULL); // close the logfile glog(NULL); return EXIT_SUCCESS; }
int MessageBox(HWND *dummy, const char *text, const char *caption, UINT type) { bool toggle_screen = false; int ret = IDOK; if (enabler.is_fullscreen()) { enabler.toggle_fullscreen(); toggle_screen = true; } # ifdef __APPLE__ // Cocoa code if (type & MB_YESNO) { ret = CocoaAlertPanel(caption, text, "Yes", "No", NULL); ret = (ret == 0 ? IDNO : IDYES); } else { CocoaAlertPanel(caption, text, "OK", NULL, NULL); } # else // GTK code if (getenv("DISPLAY")) { // Have X, will dialog GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, type & MB_YESNO ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_ERROR, type & MB_YESNO ? GTK_BUTTONS_YES_NO : GTK_BUTTONS_OK, "%s", text); gtk_window_set_position((GtkWindow*)dialog, GTK_WIN_POS_CENTER_ALWAYS); gtk_window_set_title((GtkWindow*)dialog, caption); gint dialog_ret = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); while (gtk_events_pending()) gtk_main_iteration(); if (type & MB_YESNO) { switch (dialog_ret) { default: case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_NO: ret = IDNO; break; case GTK_RESPONSE_YES: ret = IDYES; break; } } } else { // Use curses init_curses(); erase(); gps.force_full_display_count = 1; wattrset(*stdscr_p, A_NORMAL | COLOR_PAIR(1)); mvwaddstr(*stdscr_p, 0, 5, caption); mvwaddstr(*stdscr_p, 2, 2, text); nodelay(*stdscr_p, false); if (type & MB_YESNO) { mvwaddstr(*stdscr_p, 5, 0, "Press 'y' or 'n'."); refresh(); while (1) { char i = wgetch(*stdscr_p); if (i == 'y') { ret = IDYES; break; } else if (i == 'n') { ret = IDNO; break; } } } else { mvwaddstr(*stdscr_p, 5, 0, "Press any key to continue."); refresh(); wgetch(*stdscr_p); } nodelay(*stdscr_p, -1); } # endif if (toggle_screen) { enabler.toggle_fullscreen(); } return ret; }