Example #1
0
File: tasknc.c Project: skn/tasknc
void force_redraw() /* {{{ */
{
	/* force a redraw of active windows */
	WINDOW *windows[] = {statusbar, tasklist, pager, header};
	const int nwins = sizeof(windows)/sizeof(WINDOW *);
	int i;

	/* force a resize check */
	handle_resize();

	/* wipe windows */
	for (i=0; i<nwins; i++)
	{
		wattrset(windows[i], COLOR_PAIR(0));
		if (windows[i]==NULL)
			continue;
		wipe_window(windows[i]);
		wnoutrefresh(windows[i]);
	}
	doupdate();

	/* print messages */
	print_header();
	tasklist_print_task_list();
	statusbar_message(cfg.statusbar_timeout, "redrawn");
} /* }}} */
Example #2
0
File: tasknc.c Project: skn/tasknc
void handle_resize() /* {{{ */
{
	/* handle a change in screen size */
	int pagerheight;

	/* make sure rows and cols are set correctly */
	rows = getmaxy(stdscr);
	cols = getmaxx(stdscr);

	/* resize windows */
	wresize(header, 1, cols);
	wresize(tasklist, rows-2, cols);
	wresize(statusbar, 1, cols);

	/* move to proper positions */
	mvwin(header, 0, 0);
	mvwin(tasklist, 1, 0);
	mvwin(statusbar, rows-1, 0);

	/* handle pager */
	if (pager != NULL)
	{
		pagerheight = getmaxy(pager);
		if (pagerheight > rows-2)
			pagerheight = rows-2;
		wresize(pager, pagerheight, cols);
		mvwin(pager, rows-pagerheight-1, 0);
	}

	/* redraw windows */
	tasklist_print_task_list();
	print_header();

	/* message about resize */
	tnc_fprintf(logfp, LOG_DEBUG, "window resized to y=%d x=%d", rows, cols);
	statusbar_message(cfg.statusbar_timeout, "window resized to y=%d x=%d", rows, cols);
} /* }}} */
Example #3
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();
	}
} /* }}} */