Ejemplo n.º 1
0
int main(void)
{
	char word[7];
	int x,w,r;

	srandom((unsigned)time(NULL));	/* seed randomizer */
	word[6] = '\0';
	initscr();

/* Fill most of the screen with random 6-char words */
	for(x=0;x<200;x++)
	{
		for(w=0;w<6;w++)
			word[w] = (random() % 26) + 'a';
		printw("%s\t",word);
	}
	addch('\n');
	addstr("Press Enter to write this screen to disk\n");
	refresh();
	getch();

/* write the window to disk */
	r = scr_dump(FILENAME);
	if( r == ERR)
		addstr("Error writing window to disk\n");
	else
		addstr("File written; press Enter to quit\n");
	refresh();
	getch();

	endwin();
	return 0;
}
Ejemplo n.º 2
0
void printDeck(Card *deck, const char *faces[], const char *suits[]) 
/*  the ncurses library accepts the user input from the keyboard. 
*   The for loop limits the amount the cards that will print to a deck of 52. It prints a card to the screen enters 
*   into an if statement that waits for a second with the sleep() function the prints another card.  
*   The nested if is used for slapping. If the user hits the up arrow key the card is slapped. 
*/
{
    int loop;
    // print the deck one card at a time

    //fp = fopen("cardsprinted.txt", "w+");
   // t = ftell(fp);
    int c; 

    freopen("/dev/tty", "rw", stdin);

    initscr(); // intializes the 'window'
    cbreak();
    nodelay(stdscr,TRUE); // allows for the user to input at any time
    keypad(stdscr,TRUE); // enables keypad/arrow support

    for (loop = 0; loop < 52; loop++) 
    {

        //fprintf(fp,"%s of %s\n",faces[deck[loop].face],suits[deck[loop].suit]);
        //fseek(fp, t, SEEK_SET); // finds begining of the file
        //fseek(fp,t,SEEK_END);// finds end of file for printing

        // print the face and suit of the card to stdout as well as file
        printw("%s of %s\n",faces[deck[loop].face],suits[deck[loop].suit]);
        refresh();


        // loop to pause for 3seconds before printing next card. 
    
      if ((loop % 1) == 0 && loop != 0)
      { 
        sleep(1);
        c=getch();
        if (c == KEY_UP)
        {
          scr_dump("cardsfromwindow.txt");
          printw("\nYou Slapped!\n");
          refresh();
          //endwin(); 
          break;
        } 
      }
    }
    
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
    int ch;
    int which = 0;
    int last;
    bool replaying = FALSE;
    bool done = FALSE;
    char **files;

    while ((ch = getopt(argc, argv, "ir")) != -1) {
	switch (ch) {
	case 'i':
	    use_init = TRUE;
	    break;
	case 'r':
	    replaying = TRUE;
	    break;
	default:
	    usage();
	    break;
	}
    }

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    curs_set(0);
    if (has_colors()) {
	start_color();
	for (ch = 0; ch < COLOR_PAIRS; ++ch) {
	    short pair = ch % COLOR_PAIRS;
	    init_pair(pair, COLOR_WHITE, ch % COLORS);
	}
    }

    files = argv + optind;
    last = argc - optind - 1;
    if (replaying) {

	/*
	 * Use the last file as the initial/current screen.
	 */
	if (last < 0) {
	    endwin();
	    printf("No screen-dumps given\n");
	    ExitProgram(EXIT_FAILURE);
	}

	which = last;
	if (load_screen(files[which]) == ERR) {
	    endwin();
	    printf("Cannot load screen-dump %s\n", files[which]);
	    ExitProgram(EXIT_FAILURE);
	}
	after_load();

	while (!done && (ch = getch()) != ERR) {
	    switch (ch) {
	    case 'n':
		/*
		 * If we got a "next" here, skip to the final screen before
		 * moving to the next process.
		 */
		setup_next();
		which = last;
		done = TRUE;
		break;
	    case 'q':
		endwin();
		cleanup(files);
		done = TRUE;
		break;
	    case KEY_BACKSPACE:
	    case '\b':
		if (--which < 0)
		    which = last;
		break;
	    case ' ':
		if (++which > last)
		    which = 0;
		break;
	    default:
		beep();
		continue;
	    }

	    if (ch == 'q') {
		;
	    } else if (scr_restore(files[which]) == ERR) {
		endwin();
		printf("Cannot load screen-dump %s\n", files[which]);
		cleanup(files);
		ExitProgram(EXIT_FAILURE);
	    } else {
		wrefresh(curscr);
	    }
	}
    } else {
	int y;
	int x;

	move(2, 0);
	printw("Use h,j,k,l or arrows to move around the screen\n");
	printw("Press 'q' to quit, ' ' to dump a screen\n");
	printw("When the last screen has been dumped, press 'n' to run the\n");
	printw("screen-loader.  That allows only 'q', backspace and ' ' for\n");
	printw("stepping through the dumped/restored screens.\n");
	getyx(stdscr, y, x);

	while (!done) {
	    switch (ch = get_command(which, last)) {
	    case 'n':
		setup_next();
		done = TRUE;
		break;
	    case 'q':
		endwin();
		cleanup(files);
		done = TRUE;
		break;
	    case ' ':
		if (files[which] != 0) {
		    show_what(which + 1, last);
		    if (scr_dump(files[which]) == ERR) {
			endwin();
			printf("Cannot write screen-dump %s\n", files[which]);
			cleanup(files);
			done = TRUE;
			break;
		    }
		    ++which;
		    if (has_colors()) {
			short pair = which % COLOR_PAIRS;
			bkgd(COLOR_PAIR(pair));
		    }
		} else {
		    beep();
		}
		break;
	    case KEY_LEFT:
	    case 'h':
		if (--x < 0)
		    x = COLS - 1;
		break;
	    case KEY_DOWN:
	    case 'j':
		if (++y >= LINES)
		    y = 1;
		break;
	    case KEY_UP:
	    case 'k':
		if (--y < 1)
		    y = LINES - 1;
		break;
	    case KEY_RIGHT:
	    case 'l':
		if (++x >= COLS)
		    x = 0;
		break;
	    }
	    if (!done) {
		time_t now = time((time_t *) 0);

		move(0, 0);
		addstr(ctime(&now));
		move(y, x);
		addch('#' | A_REVERSE);
		move(y, x);
	    }
	}
    }
    ExitProgram(EXIT_SUCCESS);
}
Ejemplo n.º 4
0
void handle_command(char *cmdstr) /* {{{ */
{
	/* accept a command string, determine what action to take, and execute */
	char *command, *args, *modestr, *pos;
	funcmap *fmap;
	prog_mode mode;
	int ret = 0;

	/* parse args */
	pos = strchr(cmdstr, '\n');
	if (pos != NULL)
		*pos = 0;
	tnc_fprintf(logfp, LOG_DEBUG, "command received: %s", cmdstr);
	if (cmdstr != NULL)
		ret = sscanf(cmdstr, "%ms %m[^\n]", &command, &args);
	if (ret < 1)
	{
		statusbar_message(cfg.statusbar_timeout, "failed to parse command");
		tnc_fprintf(logfp, LOG_ERROR, "failed to parse command: [%d] (%s)", ret, cmdstr);
		return;
	}

	/* determine mode */
	if (pager != NULL)
	{
		modestr = "pager";
		mode = MODE_PAGER;
	}
	else if (tasklist != NULL)
	{
		modestr = "tasklist";
		mode = MODE_TASKLIST;
	}
	else
	{
		modestr = "none";
		mode = MODE_ANY;
	}

	/* log command */
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "command: %s - %s (%s)", modestr, command, args);

	/* handle command & arguments */
	/* try for exposed command */
	fmap = find_function(command, mode);
	if (fmap!=NULL)
	{
		(fmap->function)(str_trim(args));
		goto cleanup;
	}
	/* version: print version string */
	if (str_eq(command, "version"))
		statusbar_message(cfg.statusbar_timeout, "%s %s by %s\n", PROGNAME, PROGVERSION, PROGAUTHOR);
	/* quit/exit: exit tasknc */
	else if (str_eq(command, "quit") || str_eq(command, "exit"))
		done = true;
	/* reload: force reload of task list */
	else if (str_eq(command, "reload"))
	{
		reload = true;
		statusbar_message(cfg.statusbar_timeout, "task list reloaded");
	}
	/* redraw: force redraw of screen */
	else if (str_eq(command, "redraw"))
		redraw = true;
	/* dump: write all displayed tasks to log file */
	else if (str_eq(command, "dump"))
	{
		task *this = head;
		int counter = 0;
		while (this!=NULL)
		{
			tnc_fprintf(logfp, 0, "uuid: %s", this->uuid);
			tnc_fprintf(logfp, 0, "description: %s", this->description);
			tnc_fprintf(logfp, 0, "project: %s", this->project);
			tnc_fprintf(logfp, 0, "tags: %s", this->tags);
			this = this->next;
			counter++;
		}
		tnc_fprintf(logfp, 0, "dumped %d tasks", counter);
	}
	/* scrdump: do an ncurses scr_dump */
	else if (str_eq(command, "scrdump"))
	{
		const char *dumppath = "nc_dump";
		scr_dump(dumppath);
		tnc_fprintf(logfp, LOG_DEBUG, "ncurses dumped to '%s'", dumppath);
	}
	else
	{
		statusbar_message(cfg.statusbar_timeout, "error: command %s not found", command);
		tnc_fprintf(logfp, LOG_ERROR, "error: command %s not found", command);
	}
	goto cleanup;

cleanup:
	/* clean up */
	free(command);
	free(args);
} /* }}} */