void key_tasklist_search_next(void) { /* {{{ */ /* handle a keyboard direction to move to next search result */ if (searchstring != NULL) { find_next_search_result(head, get_task_by_position(selline)); tasklist_check_curs_pos(); redraw = true; } else { statusbar_message(cfg.statusbar_timeout, "no active search string"); } } /* }}} */
void key_tasklist_delete(void) { /* {{{ */ /* complete selected task */ struct task* cur = get_task_by_position(selline); int ret; statusbar_message(cfg.statusbar_timeout, "deleting task"); ret = task_background_command("task %s delete"); tasklist_remove_task(cur); tasklist_command_message(ret, "delete failed (%d)", "delete successful"); } /* }}} */
void test_search() /* {{{ */ { /* test search functionality */ char *addcmdstr, *testcmdstr, *tmp; const char *proj = "test123"; const char pri = 'H'; const char *unique = "simple"; FILE *cmdout; task *this; bool pass; asprintf(&addcmdstr, "task add pro:%s pri:%c %s", proj, pri, unique); cmdout = popen(addcmdstr, "r"); pclose(cmdout); free_tasks(head); head = get_tasks(NULL); stdout = devnull; searchstring = strdup(unique); find_next_search_result(head, head); stdout = out; this = get_task_by_position(selline); pass = strcmp(this->project, proj)==0 && this->priority==pri; test_result("search", pass); if (!pass) { puts(addcmdstr); tmp = var_value_message(find_var("search_string"), 1); puts(tmp); free(tmp); puts("selected:"); printf("uuid: %s\n", this->uuid); printf("description: %s\n", this->description); printf("project: %s\n", this->project); printf("tags: %s\n", this->tags); fflush(stdout); asprintf(&testcmdstr, "task list %s", unique); system(testcmdstr); free(testcmdstr); } cmdout = popen("task undo", "r"); pclose(cmdout); free(addcmdstr); } /* }}} */
void key_tasklist_search(const char* arg) { /* {{{ */ /* handle a keyboard direction to search * arg - the string to search for (pass NULL to prompt user) */ check_free(searchstring); if (arg == NULL) { /* store search string */ statusbar_getstr(&searchstring, "/"); wipe_statusbar(); } else { searchstring = strdup(arg); } /* go to first result */ find_next_search_result(head, get_task_by_position(selline)); tasklist_check_curs_pos(); redraw = true; } /* }}} */
void key_tasklist_toggle_started() /* {{{ */ { /* toggle whether a task is started */ bool started; time_t now; task *cur = get_task_by_position(selline); char *cmdstr, *action, *actionpast, *reply; FILE *cmdout; int ret; /* check whether task is started */ started = cur->start>0; /* generate command */ cmdstr = calloc(UUIDLENGTH+16, sizeof(char)); strcpy(cmdstr, "task "); strcat(cmdstr, cur->uuid); action = started ? " stop" : " start"; strcat(cmdstr, action); /* run command */ cmdout = popen(cmdstr, "r"); free(cmdstr); ret = pclose(cmdout); /* check return value */ if (WEXITSTATUS(ret)==0) { time(&now); cur->start = started ? 0 : now; actionpast = started ? "stopped" : "started"; asprintf(&reply, "task %s", actionpast); /* reset cached colors */ cur->pair = -1; cur->selpair = -1; } else asprintf(&reply, "task%s failed (%d)", action, WEXITSTATUS(ret)); statusbar_message(cfg.statusbar_timeout, reply); free(reply); } /* }}} */
void key_tasklist_sort(const char* arg) { /* {{{ */ /* handle a keyboard direction to sort * arg - the mode to sort by (pass NULL to prompt user) * see the manual page for how sort strings are parsed */ char* uuid = NULL; /* store selected task */ struct task* cur = get_task_by_position(selline); if (cur != NULL) { uuid = strdup(cur->uuid); } tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "sort: initial task uuid=%s", uuid); check_free(cfg.sortmode); if (arg == NULL) { /* store sort string */ cfg.sortmode = calloc(cols, sizeof(char)); statusbar_getstr(&(cfg.sortmode), "sort by: "); sb_timeout = time(NULL) + 3; } else { cfg.sortmode = strdup(arg); } /* run sort */ sort_wrapper(head); /* follow original task */ if (cfg.follow_task) { set_position_by_uuid(uuid); tasklist_check_curs_pos(); } check_free(uuid); /* force redraw */ redraw = true; } /* }}} */
void key_tasklist_edit() /* {{{ */ { /* edit selected task */ task *cur = get_task_by_position(selline); int ret; char *uuid; statusbar_message(cfg.statusbar_timeout, "editing task"); ret = task_interactive_command("task %s edit"); uuid = strdup(cur->uuid); reload_task(cur); if (cfg.follow_task) { set_position_by_uuid(uuid); tasklist_check_curs_pos(); } check_free(uuid); tasklist_command_message(ret, "edit failed (%d)", "edit succesful"); } /* }}} */
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(); } } /* }}} */
void key_tasklist_view() /* {{{ */ { /* run task info on a task and display in pager */ view_task(get_task_by_position(selline)); } /* }}} */