int umvaddstr_align(WINDOW *win, const int y, char *str) /* {{{ */ { /* evaluate an aligned string */ char *right, *pos; int ret, tmp; /* print background line */ mvwhline(win, y, 0, ' ', cols); /* find break */ pos = strstr(str, "$>"); /* end left string */ if (pos != NULL) { (*pos) = 0; right = (pos+2); } else right = NULL; /* print strings */ tmp = umvaddstr(win, y, 0, str); ret = tmp; if (right != NULL) ret = umvaddstr(win, y, cols-strlen(right), right); if (tmp > ret) ret = tmp; /* fix string */ if (pos != NULL) (*pos) = '$'; return ret; } /* }}} */
int umvaddstr_align(WINDOW *win, const int y, char *str) /* {{{ */ { /* evaluate an aligned string * win - the window to print the string in * y - the y coordinates to print the string at * str - the string to parse and print * the return is the return of the first umvaddstr, if it failed * or the return of the second umvaddstr otherwise */ char *right, *pos; int ret, tmp; /* print background line */ mvwhline(win, y, 0, ' ', cols); /* find break */ pos = strstr(str, "$>"); /* end left string */ if (pos != NULL) { (*pos) = 0; right = (pos+2); } else right = NULL; /* print strings */ tmp = umvaddstr(win, y, 0, str); ret = tmp; if (right != NULL) ret = umvaddstr(win, y, cols-strlen(right), right); if (tmp > ret) ret = tmp; /* replace the '$' in the string */ if (pos != NULL) (*pos) = '$'; return ret; } /* }}} */
int main(int argc, char **argv) /* {{{ */ { /* declare variables */ int c; bool debug = false; char *debugopts = NULL; char *logpath; /* open log */ asprintf(&logpath, LOGFILE, getenv("USER")); logfp = fopen(logpath, "a"); free(logpath); 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(); cols = COLS; rows = LINES; umvaddstr(stdscr, 0, 0, "%s %s", PROGNAME, PROGVERSION); umvaddstr(stdscr, 1, 0, "configuring..."); wrefresh(stdscr); tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "configuring..."); configure(); tnc_fprintf(logfp, LOG_DEBUG_VERBOSE, "configuration complete"); umvaddstr(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; } /* }}} */