int main() { FIELD *field[3]; FORM *my_form; WINDOW *my_form_win; int ch, rows, cols; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); /* Initialize few color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); /* Initialize the fields */ field[0] = new_field(1, 10, 6, 1, 0, 0); field[1] = new_field(1, 10, 8, 1, 0, 0); field[2] = NULL; /* Set field options */ set_field_back(field[0], A_UNDERLINE); field_opts_off(field[0], O_AUTOSKIP); /* Don't go to next field when this */ /* Field is filled up */ set_field_back(field[1], A_UNDERLINE); field_opts_off(field[1], O_AUTOSKIP); /* Create the form and post it */ my_form = new_form(field); /* Calculate the area required for the form */ scale_form(my_form, &rows, &cols); /* Create the window to be associated with the form */ my_form_win = newwin(rows + 4, cols + 4, 4, 4); keypad(my_form_win, TRUE); /* Set main window and sub window */ set_form_win(my_form, my_form_win); set_form_sub(my_form, derwin(my_form_win, rows, cols, 2, 2)); /* Print a border around the main window and print a title */ box(my_form_win, 0, 0); print_in_middle(my_form_win, 1, 0, cols + 4, "My Form", COLOR_PAIR(1)); post_form(my_form); wrefresh(my_form_win); mvprintw(LINES - 2, 0, "Use UP, DOWN arrow keys to switch between fields"); refresh(); /* Loop through to get user requests */ while((ch = wgetch(my_form_win)) != KEY_F(1)) { switch(ch) { case KEY_DOWN: /* Go to next field */ form_driver(my_form, REQ_NEXT_FIELD); /* Go to the end of the present buffer */ /* Leaves nicely at the last character */ form_driver(my_form, REQ_END_LINE); break; case KEY_UP: /* Go to previous field */ form_driver(my_form, REQ_PREV_FIELD); form_driver(my_form, REQ_END_LINE); break; default: /* If this is a normal character, it gets */ /* Printed */ form_driver(my_form, ch); break; } } /* Un post form and free the memory */ unpost_form(my_form); free_form(my_form); free_field(field[0]); free_field(field[1]); endwin(); return 0; }
int main(int argc, char* argv[]) { int is_running = 1; int x_terminal_size, y_terminal_size; memset(client_buffer, '\0', sizeof(client_buffer)); get_terminal_size(&x_terminal_size, &y_terminal_size); initscr(); raw(); keypad(stdscr, TRUE); noecho(); transcript_window = newwin(23,40,0,0); client_chat_window = newwin(MAX_ROWS,MAX_COLUMNS,20,40); write_to_transcript_window("Hello!\n"); write_to_transcript_window("Hey all!\nI love BlackChat, it's so awesome!\n"); write_to_transcript_window("Press the \'q\' key to quit!"); while(is_running) { int ch = getch(); switch(ch) { case 'q': is_running = 0; break; /* Scroll the clients typing window down. */ case KEY_DOWN: client_current_line ++; if(client_current_line*MAX_COLUMNS > strlen(client_buffer)) client_current_line --; wclear(client_chat_window); wprintw(client_chat_window, &client_buffer[client_current_line*MAX_COLUMNS]); break; /* Scroll the clients typing window up. */ case KEY_UP: client_current_line --; if(client_current_line < 0) client_current_line = 0; wclear(client_chat_window); wprintw(client_chat_window, &client_buffer[client_current_line*MAX_COLUMNS]); break; /* Delete the previous chracter. */ case KEY_BACKSPACE: client_buffer[ strlen(client_buffer)-1 ] = '\0'; print_client_chat_buffer(); break; /* If were here, that means we didn't press any "special" keys so that means were * trying to write some generic characters to our chat window. */ default: /* Store the new char in our buffer. */ client_buffer[ strlen(client_buffer) ] = ch; /* Print our new chat buffer. */ print_client_chat_buffer(); break; } wrefresh(transcript_window); wrefresh(client_chat_window); } delwin(transcript_window); delwin(client_chat_window); endwin(); return 0; }
int main() { WINDOW *my_wins[3]; PANEL *my_panels[3]; PANEL_DATA *top; PANEL *stack_top; WINDOW *temp_win, *old_win; int ch; int newx, newy, neww, newh; int size = FALSE, move = FALSE; /* Initialize curses */ initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); /* Initialize all the colors */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_CYAN, COLOR_BLACK); init_wins(my_wins, 3); /* Attach a panel to each window */ /* Order is bottom up */ my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */ my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */ my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */ set_user_ptrs(my_panels, 3); /* Update the stacking order. 2nd panel will be on top */ update_panels(); /* Show it on the screen */ attron(COLOR_PAIR(4)); mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); attroff(COLOR_PAIR(4)); doupdate(); stack_top = my_panels[2]; top = (PANEL_DATA *)panel_userptr(stack_top); newx = top->x; newy = top->y; neww = top->w; newh = top->h; while((ch = getch()) != KEY_F(1)) { switch(ch) { case 9: /* Tab */ top = (PANEL_DATA *)panel_userptr(stack_top); top_panel(top->next); stack_top = top->next; top = (PANEL_DATA *)panel_userptr(stack_top); newx = top->x; newy = top->y; neww = top->w; newh = top->h; break; case 'r': /* Re-Size*/ size = TRUE; attron(COLOR_PAIR(4)); mvprintw(LINES - 4, 0, "Entered Resizing :Use Arrow Keys to resize and press <ENTER> to end resizing"); refresh(); attroff(COLOR_PAIR(4)); break; case 'm': /* Move */ attron(COLOR_PAIR(4)); mvprintw(LINES - 4, 0, "Entered Moving: Use Arrow Keys to Move and press <ENTER> to end moving"); refresh(); attroff(COLOR_PAIR(4)); move = TRUE; break; case KEY_LEFT: if(size == TRUE) { --newx; ++neww; } if(move == TRUE) --newx; break; case KEY_RIGHT: if(size == TRUE) { ++newx; --neww; } if(move == TRUE) ++newx; break; case KEY_UP: if(size == TRUE) { --newy; ++newh; } if(move == TRUE) --newy; break; case KEY_DOWN: if(size == TRUE) { ++newy; --newh; } if(move == TRUE) ++newy; break; case 10: /* Enter */ move(LINES - 4, 0); clrtoeol(); refresh(); if(size == TRUE) { old_win = panel_window(stack_top); temp_win = newwin(newh, neww, newy, newx); replace_panel(stack_top, temp_win); win_show(temp_win, top->label, top->label_color); delwin(old_win); size = FALSE; } if(move == TRUE) { move_panel(stack_top, newy, newx); move = FALSE; } break; } attron(COLOR_PAIR(4)); mvprintw(LINES - 3, 0, "Use 'm' for moving, 'r' for resizing"); mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)"); attroff(COLOR_PAIR(4)); refresh(); update_panels(); doupdate(); } endwin(); return 0; }
int main(int argc, char **argv) { int argerr = 0; int flag; #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { /* Top-level Options */ {"verbose", 0, 0, 'V'}, {"help", 0, 0, '?'}, {"interval", 1, 0, 'i'}, {"group-by-node", 0, 0, 'n'}, {"inactive", 0, 0, 'r'}, {"as-html", 1, 0, 'h'}, {"web-cgi", 0, 0, 'w'}, {"simple-status", 0, 0, 's'}, {"as-console", 0, 0, 'c'}, {"one-shot", 0, 0, '1'}, {"daemonize", 0, 0, 'd'}, {"pid-file", 0, 0, 'p'}, {"xml-file", 1, 0, 'X'}, {0, 0, 0, 0} }; #endif pid_file = crm_strdup("/tmp/ClusterMon.pid"); crm_system_name = basename(argv[0]); crm_log_init(crm_system_name, LOG_ERR-1, FALSE, FALSE, 0, NULL); if (strcmp(crm_system_name, "crm_mon.cgi")==0) { web_cgi = TRUE; one_shot = TRUE; } while (1) { #ifdef HAVE_GETOPT_H flag = getopt_long(argc, argv, OPTARGS, long_options, &option_index); #else flag = getopt(argc, argv, OPTARGS); #endif if (flag == -1) break; switch(flag) { case 'V': cl_log_enable_stderr(TRUE); alter_debug(DEBUG_INC); break; case 'i': interval = crm_get_msec(optarg); break; case 'n': group_by_node = TRUE; break; case 'r': inactive_resources = TRUE; break; case 'd': daemonize = TRUE; break; case 'p': pid_file = crm_strdup(optarg); break; case 'X': xml_file = crm_strdup(optarg); one_shot = TRUE; break; case 'h': as_html_file = crm_strdup(optarg); break; case 'w': web_cgi = TRUE; one_shot = TRUE; break; case 'c': #if CURSES_ENABLED as_console = TRUE; #else printf("You need to have curses available at compile time to enable console mode\n"); argerr++; #endif break; case 's': simple_status = TRUE; one_shot = TRUE; break; case '1': one_shot = TRUE; break; default: printf("Argument code 0%o (%c) is not (?yet?) supported\n", flag, flag); ++argerr; break; } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); } if (argerr) { usage(crm_system_name, LSB_EXIT_GENERIC); } if(as_html_file == NULL && !web_cgi && !simple_status) { #if CURSES_ENABLED as_console = TRUE; #else printf("Defaulting to one-shot mode\n"); printf("You need to have curses available at compile time to enable console mode\n"); one_shot = TRUE; #endif } if(daemonize) { as_console = FALSE; } if(one_shot) { daemonize = FALSE; as_console = FALSE; } if(daemonize && as_html_file == NULL) { usage(crm_system_name, LSB_EXIT_GENERIC); } make_daemon(daemonize, pid_file); #if CURSES_ENABLED if(as_console) { initscr(); cbreak(); noecho(); } #endif crm_info("Starting %s", crm_system_name); mainloop = g_main_new(FALSE); if(one_shot == FALSE) { timer_id = Gmain_timeout_add( interval, mon_timer_popped, NULL); } else if(xml_file != NULL) { FILE *xml_strm = fopen(xml_file, "r"); crm_data_t *cib_object = NULL; if(strstr(xml_file, ".bz2") != NULL) { cib_object = file2xml(xml_strm, TRUE); } else { cib_object = file2xml(xml_strm, FALSE); } if(xml_strm != NULL) { fclose(xml_strm); } one_shot = TRUE; mon_update(NULL, 0, cib_ok, cib_object, NULL); } mon_timer_popped(NULL); g_main_run(mainloop); return_to_orig_privs(); crm_info("Exiting %s", crm_system_name); #if CURSES_ENABLED if(as_console) { echo(); nocbreak(); endwin(); } #endif return 0; }
int main (void) { int peg_A[8]; int peg_B[8]; int peg_C[8]; int disks; int choice; int index_from; char choice_from; char choice_to; int n_discs; peg my_pegs[3]; printf("Instructions on playing TOWERS OF HANOI:\nThere are\nthree pegs, labeled A, B, and C.\n\nInitially, peg A contains a certain\namount of disks, each one with a different size.\nThe disks are \nstacked\nin increasing size so that a disk is always on top of a larger one,\nforming a tower.\nThe goal of the game is to move all the disks from peg\nA to peg C.\nYou may move only one disk at a time.\n\nYou may move the\ntop disk from any peg to the top of the stack at another peg.\nThe\nonly\nlimitation is that you may not place a disk on top of one which is\nsmaller.\nYOU MAY STOP THE GAME ANYTIME BY ENTERING Q (THEN PRESSING \nTHE\nENTER KEY)"); get_number_of_disks(&disks); initialize(disks, peg_A, peg_B, peg_C); print_status(disks, peg_A, peg_B, peg_C); while (peg_C[disks-1]!=3) { validate_move_from(&choice_from, peg_A, peg_B, peg_C); if(choice_from=='Q' || choice_from=='q') { printf("1.print sol'n\n"); //sleep(10); printf("2.Display sol'n\n"); printf("3.Exit\n"); scanf("%d",&choice); switch(choice) { case 1: printsoln(disks); break; case 2: initscr(); /* Start curses mode */ cbreak(); /* Line buffering disabled. Pass on every thing */ keypad(stdscr, TRUE); curs_set(FALSE); print_in_middle(0, LINES / 2, COLS, welcome_string, NULL); scanw("%d", &n_discs); timeout(TIME_OUT); noecho(); store_n_discs = n_discs; init_pegs(my_pegs, n_discs); show_pegs(stdscr, my_pegs, n_discs); solve_hanoi(my_pegs, n_discs, 0, 1, 2); free_pegs(my_pegs, n_discs); endwin(); /* End curses mode */ break; case 3: break; } break; } validate_move_to(disks, choice_from, &choice_to,&index_from, peg_A, peg_B, peg_C); if(choice_to=='Q' || choice_to=='q') { printf("1.print sol'n\n"); //sleep(10); printf("2.Display sol'n\n"); printf("3.Exit\n"); scanf("%d",&choice); switch(choice) { case 1: printsoln(disks); break; case 2: initscr(); /* Start curses mode */ cbreak(); /* Line buffering disabled. Pass on every thing */ keypad(stdscr, TRUE); curs_set(FALSE); print_in_middle(0, LINES / 2, COLS, welcome_string, NULL); scanw("%d", &n_discs); timeout(TIME_OUT); noecho(); store_n_discs = n_discs; init_pegs(my_pegs, n_discs); show_pegs(stdscr, my_pegs, n_discs); solve_hanoi(my_pegs, n_discs, 0, 1, 2); free_pegs(my_pegs, n_discs); endwin(); /* End curses mode */ break; case 3: printf("\nExiting"); break; } break; } move_disk(disks, choice_from, choice_to, index_from,peg_A, peg_B, peg_C); print_status(disks, peg_A, peg_B, peg_C); } if(peg_C[disks-1]==3) printf("Congratulations! You won!\n"); return 0; }
int main(int argc, char *argv[]) { int right[4], guess[4], backup[4]; int halfrights,rights; int tmp,i; int tries = 3; int maxtries; int place,color; int x,y; char charbuffer[10]; char question[2]; int pplace[4]; pplace[0] = 13; pplace[1] = 15; pplace[2] = 17; pplace[3] = 19; halfrights=rights=0; srand(time(0)); printf("Can two places be the same color? (y/n) "); scanf("%s",charbuffer); strcpy(question,"n"); if (strcmp(charbuffer,question) == 0) { for (i=0;i<4;i++) { BACK: right[i] = (8.0*rand()/RAND_MAX+1.0); for (tmp=0;tmp<4;tmp++) { if (right[i] == right[tmp] && i != tmp) { goto BACK; } } guess[i] = 0; } } else { for (i=0;i<4;i++) { right[i] = (8.0*rand()/RAND_MAX+1.0); guess[i] = 0; } } for (i=0;i<4;i++) { backup[i] = right[i]; } printf("How many tries would you like? "); scanf("%i",&maxtries); printf("\n"); if (maxtries <= 0) { printf("Ok, fine.\n"); return 1; } printf("\nI have come up with a color combination. Press enter to start the game.\n"); getchar(); getchar(); initscr(); start_color(); getmaxyx(stdscr,y,x); if (y < 22) { endwin(); printf("Terminal too small\n"); return 1; } if (maxtries > (x/3-3)) { endwin(); printf("You have too many tries to be on the screen.\n"); return 1; } /* Color definations: */ init_pair(1, COLOR_WHITE, COLOR_RED); init_pair(2, COLOR_WHITE, COLOR_GREEN); init_pair(3, COLOR_WHITE, COLOR_BLUE); init_pair(4, COLOR_WHITE, COLOR_BLACK); init_pair(5, COLOR_WHITE, COLOR_MAGENTA); init_pair(6, COLOR_BLACK, COLOR_WHITE); init_pair(7, COLOR_WHITE, COLOR_CYAN); init_pair(8, COLOR_WHITE, COLOR_YELLOW); mvprintw(5,0,"Colors: 1: Red, 2: Green, 3: Blue, 4: Black"); mvprintw(6,0,"Colors: 5: Magenta, 6: White, 7: Cyan, 8: Yellow"); mvprintw(8,0,"Right colors on right places:"); mvprintw(10,0,"Right colors on wrong places:"); mvprintw(pplace[0],0,"1:"); mvprintw(pplace[1],0,"2:"); mvprintw(pplace[2],0,"3:"); mvprintw(pplace[3],0,"4:"); mvprintw(0,x/2-10,"Tries left: %i ",maxtries); GETPLACE: mvprintw(0,0,"Place:"); mvprintw(1,2," "); mvprintw(1,0,"? "); scanw("%i",&place); if (place < 1 || place > 4) { /* if the user types too many */ for (i=2;i<=x;i++) { /* cifers, we want to clean it up */ mvprintw(1,i," "); } goto GETPLACE; } GETCOLOR: mvprintw(0,0,"Color:"); mvprintw(1,2," "); move(1,2); scanw("%i",&color); if (color < 1 || color > 8) { /* same here */ for (i=2;i<=x;i++) { mvprintw(1,i," "); } goto GETCOLOR; } attrset(COLOR_PAIR(color)); mvprintw(pplace[place-1],tries,"%i",color); attrset(A_NORMAL); guess[place-1] = color; tmp = 1; for (i=0;i<4;i++) { if (guess[i] == 0) { tmp = 0; } } if (tmp) { /* All fields are filled */ mvprintw(pplace[3]+2,4,"Is that a guess? (y/n) "); refresh(); scanw("%s",charbuffer); strcpy(question,"y"); for (i=4;i<=x;i++) { mvprintw(pplace[3]+2,i," "); } if (strcmp(charbuffer,question) == 0) { for (i=0;i<4;i++) { if (right[i] == guess[i]) { /* Finds out how many right colors on right places */ rights++; /* the user has placed. */ right[i] = guess[i] = 0; /* This line makes sure this guess is not counted again */ } } for (i=0;i<4;i++) { for (tmp=0;tmp<4;tmp++) { if (guess[tmp] == right[i] && right[i] != 0) { halfrights++; guess[tmp] = right[i] = 0; /* This line makes sure this guess is not counted again */ } } } if (rights == 4) { endwin(); printf("CONGRATULATIONS!\n"); printf("You guessed the right combination!\n"); printf("You used %i tries\n", tries/3); return 0; } for (i=0;i<4;i++) { right[i] = backup[i]; /* We deleted the right[] array, we have to get it back for next check */ } mvprintw(9,tries,"%i",rights); mvprintw(11,tries,"%i",halfrights); halfrights=rights=0; for (i=0;i<4;i++) { guess[i] = 0; } tries = tries+3; maxtries--; mvprintw(0,x/2-10,"Tries left: %i ",maxtries); if (maxtries == 0) { for (i=0;i<4;i++) { attrset(COLOR_PAIR(right[i])); mvprintw(pplace[i],0,"%i",right[i]); attrset(A_NORMAL); } mvprintw(y-2,0,"Wrong, and you are out of tries..\n"); printw("Press enter to end program"); refresh(); getchar(); endwin(); return 1; } } } goto GETPLACE; endwin(); return 0; }
/* * This demonstrates the Cdk preprocess feature. */ int main (void) { /* Declare local variables. */ CDKSCREEN *cdkscreen = 0; CDKENTRY *widget = 0; WINDOW *cursesWin = 0; char *title = "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!"; char *info, *mesg[10], temp[256]; /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK colors. */ initCDKColor(); /* Create the entry field widget. */ widget = newCDKEntry (cdkscreen, CENTER, CENTER, title, 0, A_NORMAL, '.', vMIXED, 40, 0, 256, TRUE, FALSE); /* Is the widget null? */ if (widget == 0) { /* Clean up. */ destroyCDKScreen (cdkscreen); endCDK(); /* Print out a little message. */ printf ("Oops. Can't seem to create the entry box. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } setCDKEntryPreProcess (widget, entryPreProcessCB, 0); /* Activate the entry field. */ info = activateCDKEntry (widget, 0); /* Tell them what they typed. */ if (widget->exitType == vESCAPE_HIT) { mesg[0] = "<C>You hit escape. No information passed back."; mesg[1] = "", mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } else if (widget->exitType == vNORMAL) { mesg[0] = "<C>You typed in the following"; sprintf (temp, "<C>(%.*s)", (int)(sizeof(temp) - 20), info); mesg[1] = copyChar (temp); mesg[2] = ""; mesg[3] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 4); freeChar (mesg[1]); } /* Clean up and exit. */ destroyCDKEntry (widget); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }
int main(int argc, char* argv[]){ /* Initialize pseudo random number generator */ srand(time(NULL)); /* Read command line arguments */ struct basic_options op; struct multi_options mop; if (get_options(argc, argv, &op, &mop) == 1) return 1; /* Setup signal handlers */ struct sigaction newhandler; /* new settings */ sigset_t blocked; /* set of blocked sigs */ newhandler.sa_flags = SA_RESTART; /* options */ sigemptyset(&blocked); /* clear all bits */ newhandler.sa_mask = blocked; /* store blockmask */ newhandler.sa_handler = on_timer; /* handler function */ if ( sigaction(SIGALRM, &newhandler, NULL) == -1 ) perror("sigaction"); /* prepare the terminal for the animation */ setlocale(LC_ALL, ""); initscr(); /* initialize the library and screen */ cbreak(); /* put terminal into non-blocking input mode */ noecho(); /* turn off echo */ start_color(); clear(); /* clear the screen */ curs_set(0); /* hide the cursor */ use_default_colors(); init_pair(0, COLOR_WHITE, COLOR_BLACK); init_pair(1, COLOR_WHITE, COLOR_BLACK); init_pair(2, COLOR_BLACK, COLOR_BLACK); init_pair(3, COLOR_RED, COLOR_BLACK); init_pair(4, COLOR_GREEN, COLOR_BLACK); init_pair(5, COLOR_BLUE, COLOR_BLACK); init_pair(6, COLOR_YELLOW, COLOR_BLACK); init_pair(7, COLOR_MAGENTA, COLOR_BLACK); init_pair(8, COLOR_CYAN, COLOR_BLACK); color_set(0, NULL); assume_default_colors(COLOR_WHITE, COLOR_BLACK); clear(); struct state st; struct ui ui; /* Initialize the parameters of the program */ attrset(A_BOLD | COLOR_PAIR(2)); mvaddstr(0,0,"Map is generated. Please wait."); refresh(); state_init(&st, &op, &mop); ui_init(&st, &ui); clear(); /* non-blocking input */ int fd_flags = fcntl(0, F_GETFL); fcntl(0, F_SETFL, (fd_flags|O_NONBLOCK)); /* Start the real time interval timer with delay interval size */ struct itimerval it; it.it_value.tv_sec = 0; it.it_value.tv_usec = 10000; it.it_interval.tv_sec = 0; it.it_interval.tv_usec = 10000; setitimer(ITIMER_REAL, &it, NULL); refresh(); input_ready = 0; time_to_redraw = 1; if (!mop.multiplayer_flag) { /* Run the game */ run(&st, &ui); } else { if (mop.server_flag) run_server(&st, mop.clients_num, mop.val_server_port); else run_client(&st, &ui, mop.val_server_addr, mop.val_server_port, mop.val_client_port); } /* Restore the teminal state */ echo(); curs_set(1); clear(); endwin(); if (!mop.multiplayer_flag || mop.server_flag) printf ("Random seed was %i\n", st.map_seed); free(mop.val_server_addr); free(mop.val_server_port); free(mop.val_client_port); return 0; }
int main(){ WINDOW *my_win, *menu_win, *my_menu_win; ITEM **my_items; MENU *my_menu; list *FileBuffer; int height, width, startx, starty, exit = 0; int highlight = 1; int ch, c, choice = 0, i, j; char str[81]; FileBuffer = (list *)malloc(sizeof(list)); if (FileBuffer == NULL) return; InitialiseBuffer(FileBuffer); initscr(); clear(); noecho(); cbreak(); start_color(); /*Checking whether the terminal supports colors*/ if (has_colors() == FALSE){ endwin(); printf("Your terminal does not support colors\n"); } keypad(stdscr, TRUE); height = 3; width = 10; starty = (LINES - height)/2; startx = (COLS - width) / 2; refresh(); my_win = Create_NewWindow(height, width, starty, startx); mvwhline(my_win, 5, 1, ACS_HLINE, width - 1); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK); /* Create items */ my_items = (ITEM **)calloc(nchoices, sizeof(ITEM *)); for(i = 0; i < nchoices; ++i) my_items[i] = new_item(menu_options[i], menu_options[i]); /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Set menu option not to show the description */ menu_opts_off(my_menu, O_SHOWDESC); /* Create the window to be associated with the menu */ my_menu_win = newwin(0, 0, 0, 0); keypad(my_menu_win, TRUE); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 0, 0, 0, 0)); set_menu_format(my_menu, 1, 6); set_menu_mark(my_menu, " * "); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); i = 0; mvwhline(my_menu_win, 1, 0, ACS_HLINE, COLS); mvwprintw(my_menu_win, LINES - 1, 0, "Press F3 to go to the menu, F6 to exit", c); while(1){ choice = ToggleMenu(my_menu_win, my_menu, i); i = choice; switch(choice){ case 0: MenuOpen(FileBuffer, my_menu_win); break; case 1: MenuNew(FileBuffer, my_menu_win, my_menu); break; case 2: MenuSave(FileBuffer, my_menu_win); break; case 3: MenuSaveAs(FileBuffer, my_menu_win); break; case 4: MenuEdit(FileBuffer, my_menu_win); break; case 5: MenuExit(FileBuffer, my_menu_win); exit = 1; break; default: break; } if (exit) break; } /*Assertion: the user wants to exit the program*/ /* Unpost and free all the memory taken up */ unpost_menu(my_menu); free_menu(my_menu); for(j = 0; j < nchoices; ++j) free_item(my_items[j]); clrtoeol(); refresh(); /*Ending curses mode*/ endwin(); return 0; }
void greetings(){ initscr(); printw("*** LIME, The versatile line modeling engine, Ver.1.2\n*** Copyright 2006--2012, Christian Brinch <*****@*****.**>\n"); refresh(); }
int main(int argc, char *argv[]) { /***** * boolean value indicates when to break main loop * (and thus finish this configuration tool) *****/ int request_finish = 0; int current = 0; /***** menu selection related variables */ int menu_items = 5; enum state status[] = {active, active, active, active, active}; WINDOW *mainscr; /***** ncurses related variables */ int i, j; /***** load configuration */ if (loadConfiguration() == 0) { fprintf(stderr, "couldn't load configuration!"); exit(-1); } /***** setup speaker model */ model = (Model *) malloc(sizeof(Model)); initModel(model); /***** ignore Ctrl-C */ signal(SIGINT, SIG_IGN); /***** ncurses stuff */ initscr(); /***** initialize the curses library */ if (color_term != -1) /***** define dialog color pairs if terminal supports colors */ { start_color (); if ((color_term = has_colors ())) { color_term = 1; init_pair (1, COLOR_WHITE, COLOR_BLUE); init_pair (2, COLOR_YELLOW, COLOR_BLUE); init_pair (3, COLOR_BLUE, COLOR_YELLOW); init_pair (4, COLOR_YELLOW, COLOR_CYAN); } } else color_term = 0; keypad(stdscr, TRUE); /* enable keyboard mapping */ scrollok (stdscr, FALSE); cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* don't echo input */ refresh(); mainscr = popupWindow(COLS, LINES); /***** dialog window that contains the main menu */ leaveok (mainscr, FALSE); while (!request_finish) { wattrset (mainscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */ /***** * draw a box around the dialog window * and empty it. *****/ box(mainscr, 0, 0); for (i = 1; i < COLS-1; i++) for (j = 1; j < LINES-1; j++) mvwaddch(mainscr, j, i, ' '); /***** dialog header */ mvwaddstr(mainscr, 1, 2, "CVoiceControl"); mvwaddstrrght(mainscr, 1, COLS, "(c) 2000 Daniel Kiecza"); mvwaddseparator(mainscr, 2, COLS); mvwaddstrcntr(mainscr, 3, COLS, "Speaker Model Editor"); mvwaddseparator(mainscr, 4, COLS); /***** display main menu */ mvwaddstr(mainscr, 5, 2, "Please Select:"); mvwaddstr(mainscr, 5, 35, "Model:"); if (model_file_name != NULL) mvwaddstr(mainscr, 5, 42, model_file_name); else mvwaddstr(mainscr, 5, 42, "(none)"); setHighlight(mainscr, status[0], current == 0); mvwaddstr(mainscr, 7, 5,"New Speaker Model"); setHighlight(mainscr, status[1], current == 1); mvwaddstr(mainscr, 8, 5,"Load Speaker Model"); setHighlight(mainscr, status[2], current == 2); mvwaddstr(mainscr, 9, 5,"Edit Speaker Model"); setHighlight(mainscr, status[3], current == 3); mvwaddstr(mainscr, 10, 5,"Save Speaker Model"); setHighlight(mainscr, status[4], current == 4); mvwaddstr(mainscr, 11, 5,"Exit"); wmove(mainscr, 5, 17); /***** move cursor to an appropriate location */ wrefresh(mainscr); /***** refresh dialog window */ /* process the command keystroke */ switch(getch()) { case KEY_UP: /***** cursor up */ current = (current == 0 ? menu_items - 1 : current - 1); break; case KEY_DOWN: /***** cursor down */ current = (current == menu_items-1 ? 0 : current + 1); break; case ENTER: /***** handle menu selections */ case BLANK: switch (current) { case 0: /***** reset model, but make sure no data gets lost */ safeResetModel(); break; case 1: /***** load model */ if (safeResetModel()) { int max_file_length = 80; char *file_name; char show_file_name[82]; int width = 45, height = 11, i, j; /***** ncurses related variables */ WINDOW *loadscr = popupWindow (width, height); wattrset (loadscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */ /***** * draw a box around the dialog window * and empty it. *****/ werase (loadscr); box (loadscr, 0, 0); for (i = 1; i < width-1; i++) for (j = 1; j < height-1; j++) mvwaddch(loadscr, j, i, ' '); /***** dialog header */ mvwaddstr(loadscr, 1, 2, "Please enter file name:"); mvwaddseparator(loadscr, 2, width); wrefresh (loadscr); wattroff(loadscr, A_BOLD); file_name = wstringInput(loadscr, 4, 2, max_file_length, width-5, ""); /***** get file name */ /***** * show_file_name is set to "file" if the file_name is longer * than 15 characters. That way dialog messages stay within the * boundaries of the dialog *****/ if (strlen(file_name) <= 15) strcpy(show_file_name, file_name); else strcpy(show_file_name, "file"); /***** display information that model is being loaded */ wattrset (loadscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); mvwaddstr(loadscr, 6, 2, "Loading"); mvwaddstr(loadscr, 6, 10, show_file_name); mvwaddstr(loadscr, 6, 11+strlen(show_file_name), "..."); wrefresh(loadscr); if (loadModel(model, file_name, 1) == 1) /***** loading model is successful */ { mvwaddstr(loadscr, 6, 15+strlen(show_file_name), "success!"); /***** set variable model_file_name */ if (strstr(file_name, model_file_extension) != file_name+strlen(file_name)-strlen(model_file_extension)) { model_file_name = malloc(strlen(file_name) + strlen(model_file_extension) + 1); strcpy(model_file_name, file_name); strcat(model_file_name, model_file_extension); } else { model_file_name = malloc(strlen(file_name) + 1); strcpy(model_file_name, file_name); } } else /***** loading model has failed */ mvwaddstr(loadscr, 6, 15+strlen(show_file_name), "failed!"); mvwaddstrcntr(loadscr, 8, width,"Press <Space> to return to menu ..."); wrefresh(loadscr); /***** refresh dialog */ getch(); /***** wait for keyboard input */ delwin(loadscr); /***** delete ncurses dialog window */ free (file_name); } break; case 2: /***** edit the speaker model */ editModel(); break; case 3: /***** save the speaker model */ if (model->number_of_items > 0) { char *file_name; int max_file_length = 84; int width = 45, height = 11, i, j; /***** ncurses related variables */ WINDOW *savescr = popupWindow (width, height); wattrset (savescr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */ /***** * draw a box around the dialog window * and empty it. *****/ werase (savescr); box (savescr, 0, 0); for (i = 1; i < width-1; i++) for (j = 1; j < height-1; j++) mvwaddch(savescr, j, i, ' '); /***** display dialog header */ mvwaddstr(savescr, 1, 2, "Please enter file name:"); mvwaddseparator(savescr, 2, width); wrefresh (savescr); wattroff(savescr, A_BOLD); file_name = wstringInput(savescr, 4, 2, max_file_length, width-5, model_file_name); /***** get file name */ /***** display information that model is being saved */ wattrset (savescr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); mvwaddstr(savescr, 6, 2, "Saving ..."); wrefresh(savescr); if (saveModel(model, file_name) == 1) /***** saving successful */ { mvwaddstr(savescr, 6, 13, "success!"); /***** update model_file_name if necessary */ if (model_file_name != NULL && strcmp(model_file_name, file_name) != 0) { free(model_file_name); model_file_name = malloc(strlen(file_name) + 1); strcpy(model_file_name, file_name); } modified = 0; /***** switch modified to '0' */ } else /***** saving failed */ mvwaddstr(savescr, 6, 13, "failed!"); mvwaddstrcntr(savescr, 8, width,"Press <Space> to return to menu ..."); wrefresh(savescr); /***** refresh dialog */ getch(); /***** wait for keyboard input */ delwin(savescr); /***** delete ncurses dialog window */ free (file_name); } break; case 4: /***** quit program */ if (safeResetModel()) { wrefresh(mainscr); request_finish = 1; delwin(mainscr); /***** delete ncurses dialog window */ } break; } break; } } endwin(); /***** wrap up ncurses stuff */ exit(0); /***** exit program */ }
static void test_inserts(int level) { static bool first = TRUE; wint_t ch; int code; 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 * 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 += 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 ((code = wget_wch(work, &ch)) != ERR) { if (code == KEY_CODE_YES) { switch (ch) { case KEY_DOWN: ch = CTRL('N'); break; case KEY_BACKSPACE: ch = '\b'; break; default: beep(); continue; } } else if (code == ERR) { beep(); break; } if (ch == 'q') break; wmove(work, row, margin + 1); switch (ch) { case 'w': test_inserts(level + 1); touchwin(look); touchwin(work); touchwin(show); wnoutrefresh(look); wnoutrefresh(work); wnoutrefresh(show); doupdate(); break; case CTRL('N'): 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; case KEY_BACKSPACE: ch = '\b'; /* FALLTHRU */ 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(ch); } break; case oMove: MvInsCh(limit + row, col, ch); break; case oWindow: if (wmove(work, limit + row, col) != ERR) { WInsCh(work, ch); } break; case oMoveWindow: MvWInsCh(work, limit + row, col, ch); break; } wnoutrefresh(work); legend(show, level, option, buffer, length); wnoutrefresh(show); doupdate(); break; } } if (level > 0) { delwin(show); delwin(work); delwin(look); } }
void start_curses( void ) { int keypad_on = 0; if ( isatty( fileno( stdout ) ) && LYReopenInput( ) < 0 ) { fwrite( "Cannot open tty input\n", 1, 22, stderr ); exit_immediately( 1 ); } if ( LYscreen == 0 ) { BOOLEAN savesize = recent_sizechange; size_change( 0 ); recent_sizechange = savesize; if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "Screen size: %s()\n", "initscr" ); } LYscreen = initscr( ); if ( LYscreen == 0 ) { fprintf( TraceFP( ), "%s\n", gettext( "Terminal initialisation failed - unknown terminal type?" ) ); exit_immediately( 1 ); } lynx_called_initscr = 1; LYlines = LYscreenHeight( ); LYcols = LYscreenWidth( ); size_change( 0 ); recent_sizechange = 0; if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "Screen size is now %d x %d\n", LYlines, LYcols ); } if ( LYuseCursesPads ) { LYwin = newpad( LYlines, 1014 ); LYshiftWin = 0; LYwideLines = 0; } else LYwin = stdscr; keypad( LYwin, 1 ); keypad_on = 1; if ( lynx_initialize_keymaps( ) == -1 ) { endwin( ); exit_immediately( 1 ); } if ( has_colors( ) & 255 ) { lynx_has_color = 1; start_color( ); if ( COLORS > 16 ) COLORS = 16; if ( COLORS <= 7 ) COLORS = 2; if ( COLORS > 8 && COLORS != 16 ) COLORS = 8; if ( LYuse_default_colors ) { if ( assume_default_colors( default_fg, default_bg ) ) { default_fg = 7; default_bg = 0; } if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "initializing default colors %d/%d\n", default_fg, default_bg ); } if ( default_fg >= 0 || default_bg >= 0 ) { unsigned int n = 0; for ( ; n <= 7; n++ ) { if ( default_fg >= 0 && lynx_color_cfg[ n ].fg < 0 ) lynx_color_cfg[ n ].fg = default_fg; if ( default_bg >= 0 && lynx_color_cfg[ n ].bg < 0 ) lynx_color_cfg[ n ].bg = default_bg; if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "color_cfg[%u] = %d/%d\n", n, lynx_color_cfg[ n ].fg, lynx_color_cfg[ n ].bg ); } // n++; } lynx_setup_colors( ); } } } if ( lynx_lss_file && lynx_lss_file[0] && ( LYCanReadFile( lynx_lss_file ) & 255 ) ) style_readFromFile( lynx_lss_file ); parse_userstyles( ); lynx_init_colors( ); } cbreak( ); signal( 2, &cleanup_sig ); noecho( ); if ( keypad_on == 0 ) keypad( LYwin, 1 ); lynx_enable_mouse( 1 ); fflush( stdin ); fflush( stdout ); fflush( stderr ); LYCursesON = 1; if ( WWW_TraceFlag ) { fprintf( TraceFP( ), "start_curses: done.\n" ); } return; }
static void display_window(TALLOC_CTX *mem_ctx, struct registry_context *ctx) { struct regedit *regedit; struct tree_node *root; bool colors; int key; initscr(); cbreak(); noecho(); fault_configure(regedit_panic_handler); colors = has_colors(); if (colors) { start_color(); use_default_colors(); assume_default_colors(COLOR_WHITE, COLOR_BLUE); init_pair(PAIR_YELLOW_CYAN, COLOR_YELLOW, COLOR_CYAN); init_pair(PAIR_BLACK_CYAN, COLOR_BLACK, COLOR_CYAN); init_pair(PAIR_YELLOW_BLUE, COLOR_YELLOW, COLOR_BLUE); } regedit = talloc_zero(mem_ctx, struct regedit); SMB_ASSERT(regedit != NULL); regedit_main = regedit; regedit->registry_context = ctx; regedit->main_window = stdscr; keypad(regedit->main_window, TRUE); mvwprintw(regedit->main_window, 0, 0, "Path: "); regedit->path_label = newpad(1, PATH_WIDTH_MAX); SMB_ASSERT(regedit->path_label); wprintw(regedit->path_label, "/"); show_path(regedit_main); root = tree_node_new_root(regedit, ctx); SMB_ASSERT(root != NULL); regedit->keys = tree_view_new(regedit, root, KEY_HEIGHT, KEY_WIDTH, KEY_START_Y, KEY_START_X); SMB_ASSERT(regedit->keys != NULL); regedit->vl = value_list_new(regedit, VAL_HEIGHT, VAL_WIDTH, VAL_START_Y, VAL_START_X); SMB_ASSERT(regedit->vl != NULL); regedit->tree_input = true; print_heading(regedit); tree_view_show(regedit->keys); load_values(regedit); value_list_show(regedit->vl); update_panels(); doupdate(); do { key = regedit_getch(); handle_main_input(regedit, key); update_panels(); doupdate(); } while (key != 'q' || key == 'Q'); endwin(); }
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc = __argc; char **argv = __argv; #else int main(int argc, char *argv[]) { #endif #ifdef ENABLE_LOGGING setupDebug(); #endif int seed = time(NULL); // set locale to system default setlocale(LC_ALL, ""); bindtextdomain("cataclysm-dda", "lang/mo"); bind_textdomain_codeset("cataclysm-dda", "UTF-8"); textdomain("cataclysm-dda"); //args: world seeding only. argc--; argv++; while (argc){ if(std::string(argv[0]) == "--seed"){ argc--; argv++; if(argc){ seed = djb2_hash((unsigned char*)argv[0]); argc--; argv++; } } else // ignore unknown args. argc--; argv++; } // ncurses stuff load_options(); // For getting size options initscr(); // Initialize ncurses noecho(); // Don't echo keypresses cbreak(); // C-style breaks (e.g. ^C to SIGINT) keypad(stdscr, true); // Numpad is numbers init_colors(); // See color.cpp // curs_set(0); // Invisible cursor set_escdelay(10); // Make escape actually responsive std::srand(seed); bool quit_game = false; bool delete_world = false; g = new game; if(g->game_error()) exit_handler(-999); g->init_ui(); MAPBUFFER.set_game(g); g->load_artifacts(); //artifacts have to be loaded before any items are created if(g->game_error()) exit_handler(-999); MAPBUFFER.load(); curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone #if (!(defined _WIN32 || defined WINDOWS)) struct sigaction sigIntHandler; sigIntHandler.sa_handler = exit_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); #endif do { g->setup(); while (!g->do_turn()) ; if (g->uquit == QUIT_DELETE_WORLD) delete_world = true; if (g->game_quit() || g->game_error()) quit_game = true; } while (!quit_game); if (delete_world) { g->delete_save(); } else { MAPBUFFER.save_if_dirty(); } exit_handler(-999); return 0; }
static WINDOW * ncurses_setup(void){ struct ncurses_input_marshal *nim; const char *errstr = NULL; WINDOW *w = NULL; fprintf(stderr,"Entering ncurses mode...\n"); if(initscr() == NULL){ fprintf(stderr,"Couldn't initialize ncurses\n"); return NULL; } if(cbreak() != OK){ errstr = "Couldn't disable input buffering\n"; goto err; } if(noecho() != OK){ errstr = "Couldn't disable input echoing\n"; goto err; } if(intrflush(stdscr,TRUE) != OK){ errstr = "Couldn't set flush-on-interrupt\n"; goto err; } if(scrollok(stdscr,FALSE) != OK){ errstr = "Couldn't disable scrolling\n"; goto err; } if(nonl() != OK){ errstr = "Couldn't disable nl translation\n"; goto err; } if(start_color() != OK){ errstr = "Couldn't initialize ncurses color\n"; goto err; } if(use_default_colors()){ errstr = "Couldn't initialize ncurses colordefs\n"; goto err; } w = stdscr; ESCDELAY = 100; keypad(stdscr,TRUE); if(nodelay(stdscr,FALSE) != OK){ errstr = "Couldn't set blocking input\n"; goto err; } if(curs_set(0) == ERR){ errstr = "Couldn't disable cursor\n"; goto err; } if(setup_statusbar(COLS)){ errstr = "Couldn't setup status bar\n"; goto err; } if(COLORS < 16){ assert(init_pair(BORDER_COLOR,COLOR_GREEN,-1) == OK); assert(init_pair(HEADER_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(FOOTER_COLOR,COLOR_YELLOW,-1) == OK); assert(init_pair(DBORDER_COLOR,COLOR_WHITE,-1) == OK); assert(init_pair(DHEADING_COLOR,COLOR_WHITE,-1) == OK); assert(init_pair(UBORDER_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(UHEADING_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(PBORDER_COLOR,COLOR_YELLOW,-1) == OK); assert(init_pair(PHEADING_COLOR,COLOR_RED,-1) == OK); assert(init_pair(BULKTEXT_COLOR,COLOR_WHITE,-1) == OK); assert(init_pair(BULKTEXT_ALTROW_COLOR,COLOR_WHITE,-1) == OK); assert(init_pair(IFACE_COLOR,COLOR_WHITE,-1) == OK); assert(init_pair(LCAST_COLOR,COLOR_CYAN,-1) == OK); // will use A_BOLD via OUR_BOLD assert(init_pair(UCAST_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(MCAST_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(BCAST_COLOR,COLOR_MAGENTA,-1) == OK); assert(init_pair(LSELECTED_COLOR,-1,COLOR_CYAN) == OK); assert(init_pair(USELECTED_COLOR,-1,COLOR_CYAN) == OK); assert(init_pair(MSELECTED_COLOR,-1,COLOR_BLUE) == OK); assert(init_pair(BSELECTED_COLOR,-1,COLOR_MAGENTA) == OK); assert(init_pair(LCAST_L3_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(UCAST_L3_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(MCAST_L3_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(BCAST_L3_COLOR,COLOR_MAGENTA,-1) == OK); assert(init_pair(LCAST_RES_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(UCAST_RES_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(MCAST_RES_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(BCAST_RES_COLOR,COLOR_MAGENTA,-1) == OK); assert(init_pair(LCAST_ALTROW_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(UCAST_ALTROW_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(MCAST_ALTROW_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(BCAST_ALTROW_COLOR,COLOR_MAGENTA,-1) == OK); assert(init_pair(LCAST_ALTROW_L3_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(UCAST_ALTROW_L3_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(MCAST_ALTROW_L3_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(BCAST_ALTROW_L3_COLOR,COLOR_MAGENTA,-1) == OK); assert(init_pair(LCAST_ALTROW_RES_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(UCAST_ALTROW_RES_COLOR,COLOR_CYAN,-1) == OK); assert(init_pair(MCAST_ALTROW_RES_COLOR,COLOR_BLUE,-1) == OK); assert(init_pair(BCAST_ALTROW_RES_COLOR,COLOR_MAGENTA,-1) == OK); assert(init_pair(SUBDISPLAY_COLOR,COLOR_WHITE,-1) == OK); }else{ int z; assert(init_pair(BORDER_COLOR,COLOR_ALUMINIUM,-1) == OK); assert(init_pair(HEADER_COLOR,COLOR_MODBLUE,-1) == OK); assert(init_pair(FOOTER_COLOR,COLOR_MODYELLOW,-1) == OK); assert(init_pair(DBORDER_COLOR,COLOR_ALUMINIUM,-1) == OK); assert(init_pair(DHEADING_COLOR,COLOR_MODWHITE,-1) == OK); assert(init_pair(UBORDER_COLOR,COLOR_MODCYAN,-1) == OK); assert(init_pair(UHEADING_COLOR,COLOR_ORANGE,-1) == OK); assert(init_pair(PBORDER_COLOR,COLOR_MODBLUE,-1) == OK); assert(init_pair(PHEADING_COLOR,COLOR_MODRED,-1) == OK); assert(init_pair(BULKTEXT_COLOR,COLOR_MODWHITE,-1) == OK); assert(init_pair(BULKTEXT_ALTROW_COLOR,COLOR_MODWHITE,COLOR_PALEALUMINIUM) == OK); assert(init_pair(IFACE_COLOR,COLOR_MODWHITE,-1) == OK); assert(init_pair(LCAST_COLOR,COLOR_CHAMELEON,-1) == OK); assert(init_pair(UCAST_COLOR,COLOR_MODBLUE,-1) == OK); assert(init_pair(MCAST_COLOR,COLOR_SKYBLUE,-1) == OK); assert(init_pair(BCAST_COLOR,COLOR_MODVIOLET,-1) == OK); assert(init_pair(LSELECTED_COLOR,COLOR_MODWHITE,COLOR_CHAMELEON_50) == OK); assert(init_pair(USELECTED_COLOR,COLOR_MODWHITE,COLOR_BLUE_50) == OK); assert(init_pair(MSELECTED_COLOR,COLOR_MODWHITE,COLOR_SKYBLUE_50) == OK); assert(init_pair(BSELECTED_COLOR,COLOR_MODWHITE,COLOR_VIOLET_50) == OK); assert(init_pair(LCAST_L3_COLOR,COLOR_CHAMELEON_75,-1) == OK); assert(init_pair(UCAST_L3_COLOR,COLOR_BLUE_75,-1) == OK); assert(init_pair(MCAST_L3_COLOR,COLOR_SKYBLUE_75,-1) == OK); assert(init_pair(BCAST_L3_COLOR,COLOR_VIOLET_75,-1) == OK); assert(init_pair(LCAST_RES_COLOR,COLOR_CHAMELEON_50,-1) == OK); assert(init_pair(UCAST_RES_COLOR,COLOR_BLUE_50,-1) == OK); assert(init_pair(MCAST_RES_COLOR,COLOR_SKYBLUE_50,-1) == OK); assert(init_pair(BCAST_RES_COLOR,COLOR_VIOLET_50,-1) == OK); // Disable altrow stuff for now. It's hard to read and ugly. assert(init_pair(LCAST_ALTROW_COLOR,COLOR_CHAMELEON,-1) == OK); assert(init_pair(UCAST_ALTROW_COLOR,COLOR_MODBLUE,-1) == OK); assert(init_pair(MCAST_ALTROW_COLOR,COLOR_SKYBLUE,-1) == OK); assert(init_pair(BCAST_ALTROW_COLOR,COLOR_MODVIOLET,-1) == OK); assert(init_pair(LCAST_ALTROW_L3_COLOR,COLOR_CHAMELEON_75,-1) == OK); assert(init_pair(UCAST_ALTROW_L3_COLOR,COLOR_BLUE_75,-1) == OK); assert(init_pair(MCAST_ALTROW_L3_COLOR,COLOR_SKYBLUE_75,-1) == OK); assert(init_pair(BCAST_ALTROW_L3_COLOR,COLOR_VIOLET_75,-1) == OK); assert(init_pair(LCAST_ALTROW_RES_COLOR,COLOR_CHAMELEON_50,-1) == OK); assert(init_pair(UCAST_ALTROW_RES_COLOR,COLOR_BLUE_50,-1) == OK); assert(init_pair(MCAST_ALTROW_RES_COLOR,COLOR_SKYBLUE_50,-1) == OK); assert(init_pair(BCAST_ALTROW_RES_COLOR,COLOR_VIOLET_50,-1) == OK); assert(init_pair(SUBDISPLAY_COLOR,COLOR_MODWHITE,-1) == OK); for(z = FIRST_FREE_COLOR ; z < COLORS && z < COLOR_PAIRS ; ++z){ assert(init_pair(z,z,-1) == OK); } } if(draw_main_window(w)){ errstr = "Couldn't use ncurses\n"; goto err; } if((nim = malloc(sizeof(*nim))) == NULL){ goto err; } nim->w = w; nim->maintid = pthread_self(); // Panels aren't yet being used, so we need call refresh() to // paint the main window. refresh(); if(pthread_create(&inputtid,NULL,ncurses_input_thread,nim)){ errstr = "Couldn't create UI thread\n"; free(nim); goto err; } // FIXME install SIGWINCH() handler...? return w; err: mandatory_cleanup(&w); fprintf(stderr,"%s",errstr); return NULL; }
int main(int argc, char *argv[]) { world_t world; unsigned int each_iteration; unsigned int each_organism; unsigned int x; unsigned int y; char c; char color; organism_t organisms[ORGANISM_COUNT]; srandom(RANDOM_SEED); #if CURSES_VISUALIZATION initscr(); start_color(); #if CURSES_SOLID_COLORS init_pair(1, COLOR_BLACK, COLOR_RED); init_pair(2, COLOR_BLACK, COLOR_GREEN); init_pair(3, COLOR_BLACK, COLOR_BLUE); init_pair(4, COLOR_BLACK, COLOR_WHITE); init_pair(5, COLOR_BLACK, COLOR_BLACK); #else init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_WHITE, COLOR_BLACK); init_pair(5, COLOR_BLACK, COLOR_BLACK); #endif #endif create_world(&world); for (each_organism = 0; each_organism < ORGANISM_COUNT; each_organism++) { create_organism(&world, &organisms[each_organism]); } for (each_iteration = 0; each_iteration < ITERATIONS; each_iteration++) { for (each_organism = 0; each_organism < ORGANISM_COUNT; each_organism++) { move_organism(&world, &organisms[each_organism]); } #if CURSES_VISUALIZATION for (x = 0; x < WORLD_WIDTH; x++) { for (y = 0; y < WORLD_HEIGHT; y++) { if (NULL == world.cells[x][y]) { color = 'x'; c = ' '; } else { color = display_color(world.cells[x][y]); c = world.cells[x][y]->face; } switch (color) { case 'r': mvaddch(y, x, c | COLOR_PAIR(1)); break; case 'g': mvaddch(y, x, c | COLOR_PAIR(2)); break; case 'b': mvaddch(y, x, c | COLOR_PAIR(3)); break; case 'w': mvaddch(y, x, c | COLOR_PAIR(4)); break; default: mvaddch(y, x, c | COLOR_PAIR(5)); break; } } } refresh(); usleep(SLEEP_US); #endif } for (each_organism = 0; each_organism < ORGANISM_COUNT; each_organism++) { destroy_organism(&world, &organisms[each_organism]); } #if CURSES_VISUALIZATION endwin(); #endif return 0; }
int main(int argc, char* argv[]) { initscr(); // initialize ncurses display nodelay(stdscr, 1); // don't wait for key presses noecho(); // don't echo key presses gz_spi_set_width(2); // Pass blocks of 2 bytes on SPI gz_clock_ena(GZ_CLK_5MHz, 80); // 250 kHz erase(); outputs_off(); printw("Modulating PWMs.\n"); printw("Press 'n' for next test, any other key to stop.\n"); int key = 0; while(1) { exercise_pwms(); key = getch(); if (key != -1) { break; } } if (key == 'n') { printw("Toggling all outputs.\n"); printw("Press 'n' for next test, any other key to stop.\n"); while(1) { exercise_outputs(0xff, 0x00); key = getch(); if (key != -1) { break; } } } if (key == 'n') { erase(); printw("Toggling alternate outputs.\n"); printw("Press 'n' for next test, any other key to stop.\n"); while(1) { exercise_outputs(0xaa, 0x55); key = getch(); if (key != -1) { break; } } } if (key == 'n') { erase(); printw("Walking outputs.\n"); printw("Press 'n' for next test, any other key to stop.\n"); unsigned char current = 0xfe; while(1) { exercise_outputs(current, (current << 1) | 0x01); current = (current << 2) | 0x03; if (current == 0xff) { current = 0xfe; } key = getch(); if (key != -1) { break; } } } if (key == 'n') { erase(); curs_set(0); // Hide the cursor printw("Reading inputs.\n"); printw("Press any key to stop.\n"); while(1) { display_inputs(); key = getch(); if (key != -1) { break; } } move(getcury(stdscr) + 1 ,0); curs_set(1); refresh(); } gz_spi_close(); // close SPI channel erase(); reset_shell_mode(); // turn off ncurses return 0; }
int main() { int i; int x; int y; int bottomOfMaze = 0; int mazewidth = 0; char rowOfMaze[102]; char buf[102]; char userInput; FILE *smileFile; i = 0; x = 0; y = 0; initscr(); cbreak (); noecho (); bottomOfMaze = drawMaze(); refresh(); while(i==0) { userInput = getch(); i = movement(userInput, bottomOfMaze); refresh(); } if (i == 2) { move(0, 0); smileFile = fopen("face.txt", "r"); if (smileFile != NULL) { while ((fgets(buf,102, smileFile)!=NULL)||(x < 2)) { i = 0; mazewidth = strlen(buf); while (i<mazewidth) { rowOfMaze[i] = buf[i]; i++; } mvprintw(y, 0, "%s", rowOfMaze); y++; x++; } i = 0; while (i<15) { mvprintw(y, i, " "); i++; } } else { printf("There appears to be an error in opening the file"); } fclose(smileFile); getch(); } endwin(); return (0); }
void init(){ initscr(); }
void main() { #define PALSIZE 8 char *palette=" -=*O@@@@_"; srand(time(NULL)); // Needed initscr(); cbreak(); noecho(); // Optional nonl(); intrflush(stdscr,FALSE); keypad(stdscr,FALSE); printf("%i x %i\n",COLS,LINES); if (has_colors()) { start_color(); init_pair(0,COLOR_BLACK,COLOR_BLACK); init_pair(1,COLOR_BLUE,COLOR_BLACK); init_pair(2,COLOR_RED,COLOR_BLACK); init_pair(3,COLOR_MAGENTA,COLOR_BLACK); init_pair(4,COLOR_GREEN,COLOR_BLACK); init_pair(5,COLOR_CYAN,COLOR_BLACK); init_pair(6,COLOR_YELLOW,COLOR_BLACK); init_pair(7,COLOR_WHITE,COLOR_BLACK); } frames=0; cls(); while (true) { // doSummat(&lonewriteToPoint); cenx = COLS / 2; ceny = LINES / 2; swirlang = (float)frames * M_PI / 800.0; // Zooming in and out over time spacePerSwirl = 0.08+0.03*cos(0.000638*(float)frames); move(0,0); attrset(COLOR_PAIR(2) | A_BOLD); for (int y = 0;y<LINES;y++) { for (int x = 0;x<COLS;x++) { float swirlHeight=getSwirlHeight(x,y); { int c= ( getSwirlHeight(x+1,y+1) > 0 ? 1 : 0 ) + ( getSwirlHeight(x,y+1) > 0 ? 1 : 0 ) + ( getSwirlHeight(x+1,y) > 0 ? 1 : 0 ) + ( getSwirlHeight(x,y) > 0 ? 1 : 0 ) + ( getSwirlHeight((float)x+0.5,(float)y+0.5) > 0 ? 1 : 0 ); char ch = palette[c]; // mvaddch(y,x,32); addch(ch); } } } // int x = frames%COLS; // int y = (frames/COLS)%LINES; // move(y,x); // attrset(COLOR_PAIR(7)); // char *str; // sprintf(str," (- %i -) ",frames); // addstr(str); // printf("%i ",frames); // move(1,0); // attrset(COLOR_PAIR(0)); // printf("%i ",frames); wrefresh(stdscr); frames += 10; } cls(); // Needed endwin(); }