Ejemplo n.º 1
0
static bool
validate_rows_and_columns(const struct gol *g) {
    if (LINES < g->rows) {
        ncurses_end();
        fprintf(stderr, "rows option is larger than screen\n");
        return false;
    }
    if (COLS < g->columns) {
        ncurses_end();
        fprintf(stderr, "columns option is larger than screen\n");
        return false;
    }
    return true;
}
Ejemplo n.º 2
0
void tasklist_window() /* {{{ */
{
	/* ncurses main function */
	int c;
	task *cur;
	char *uuid = NULL;

	/* get field lengths */
	cfg.fieldlengths.project = max_project_length();
	cfg.fieldlengths.date = DATELENGTH;

	/* create windows */
	rows = LINES;
	cols = COLS;
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "rows: %d, columns: %d", rows, cols);
	header = newwin(1, cols, 0, 0);
	tasklist = newwin(rows-2, cols, 1, 0);
	statusbar = newwin(1, cols, rows-1, 0);
	tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "ncurses windows: h:%p, t:%p, s:%p (%d,%d)", header, tasklist, statusbar, rows, cols);
	if (statusbar==NULL || tasklist==NULL || header==NULL)
	{
		tnc_fprintf(logfp, LOG_ERROR, "window creation failed (rows:%d, cols:%d)", rows, cols);
		ncurses_end(-1);
	}

	/* set curses settings */
	set_curses_mode(NCURSES_MODE_STD);

	/* print task list */
	check_screen_size();
	cfg.fieldlengths.description = COLS-cfg.fieldlengths.project-1-cfg.fieldlengths.date;
	task_count();
	print_header();
	tasklist_print_task_list();

	/* main loop */
	while (1)
	{
		/* set variables for determining actions */
		done = false;
		redraw = false;
		reload = false;

		/* check for an empty task list */
		if (head == NULL)
		{
			if (strcmp(active_filter,"") == 0){
				tnc_fprintf(logfp, LOG_ERROR, "it appears that your task list is empty. %s does not yet support empty task lists.", PROGNAME);
				ncurses_end(-1);
			}
			active_filter = strdup("");
			reload = true;
		}

		/* get the screen size */
		rows = LINES;
		cols = COLS;

		/* check for a screen thats too small */
		check_screen_size();

		/* check for size changes */
		check_resize();

		/* apply staged window updates */
		doupdate();

		/* get a character */
		c = wgetch(statusbar);

		/* handle the character */
		handle_keypress(c, MODE_TASKLIST);

		/* exit */
		if (done)
			break;
		/* reload task list */
		if (reload)
		{
			cur = get_task_by_position(selline);
			if (cur != NULL)
				uuid = strdup(cur->uuid);
			wipe_tasklist();
			reload_tasks();
			task_count();
			redraw = true;
			if (cfg.follow_task)
				set_position_by_uuid(uuid);
			check_free(uuid);
			uuid = NULL;
			tasklist_check_curs_pos();
		}
		/* redraw all windows */
		if (redraw)
		{
			cfg.fieldlengths.project = max_project_length();
			cfg.fieldlengths.description = cols-cfg.fieldlengths.project-1-cfg.fieldlengths.date;
			print_header();
			tasklist_print_task_list();
			tasklist_check_curs_pos();
			touchwin(tasklist);
			touchwin(header);
			touchwin(statusbar);
			wnoutrefresh(tasklist);
			wnoutrefresh(header);
			wnoutrefresh(statusbar);
			doupdate();
		}

		statusbar_timeout();
	}
} /* }}} */
Ejemplo n.º 3
0
Archivo: tasknc.c Proyecto: skn/tasknc
int main(int argc, char **argv) /* {{{ */
{
	/* declare variables */
	int c;
	bool debug = false;
	char *debugopts = NULL;

	/* open log */
	logfp = fopen(LOGFILE, "a");
	tnc_fprintf(logfp, LOG_DEBUG, "%s started", PROGNAME);

	/* set defaults */
	cfg.loglvl = LOGLVL_DEFAULT;
	setlocale(LC_ALL, "");

	/* handle arguments */
	static struct option long_options[] =
	{
		{"help",     no_argument,       0, 'h'},
		{"debug",    required_argument, 0, 'd'},
		{"version",  no_argument,       0, 'v'},
		{"loglevel", required_argument, 0, 'l'},
		{"filter",   required_argument, 0, 'f'},
		{0, 0, 0, 0}
	};
	int option_index = 0;
	while ((c = getopt_long(argc, argv, "l:hvd:f:", long_options, &option_index)) != -1)
	{
		switch (c)
		{
			case 'l':
				cfg.loglvl = (char) atoi(optarg);
				printf("loglevel: %d\n", (int)cfg.loglvl);
				break;
			case 'v':
				print_version();
				return 0;
				break;
			case 'd':
				debug = true;
				debugopts = strdup(optarg);
				break;
			case 'f':
				active_filter = strdup(optarg);
				break;
			case 'h':
			case '?':
				help();
				return 0;
				break;
			default:
				return 1;
		}
	}

	/* run ncurses */
	if (!debug)
	{
		tnc_fprintf(logfp, LOG_DEBUG, "running gui");
		ncurses_init();
		mvwprintw(stdscr, 0, 0, "%s %s", PROGNAME, PROGVERSION);
		mvwprintw(stdscr, 1, 0, "configuring...");
		wrefresh(stdscr);
		tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "configuring...");
		configure();
		tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "configuration complete");
		mvwprintw(stdscr, 1, 0, "loading tasks...");
		wrefresh(stdscr);
		tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "loading tasks...");
		head = get_tasks(NULL);
		tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "%d tasks loaded", taskcount);
		mvwhline(stdscr, 0, 0, ' ', COLS);
		mvwhline(stdscr, 1, 0, ' ', COLS);
		tasklist_window();
		ncurses_end(0);
	}

	/* debug mode */
	else
	{
		configure();
		head = get_tasks(NULL);
		test(debugopts);
		free(debugopts);
	}

	/* done */
	tnc_fprintf(logfp, LOG_DEBUG, "exiting");
	return 0;
} /* }}} */