From d07470e8def83488365e4d7c6b03c10c5cb86563 Mon Sep 17 00:00:00 2001 From: lshprung Date: Thu, 18 Mar 2021 12:52:59 -0700 Subject: Added new launch flags --- draw.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'draw.c') diff --git a/draw.c b/draw.c index f82435d..ac9e9ab 100644 --- a/draw.c +++ b/draw.c @@ -20,6 +20,7 @@ #define WIDTH (getmaxx(stdscr)) //width of the entire term #define HEIGHT (getmaxy(stdscr)) //height of the entire term +void print_help(char *exec_name); void update_display(bool resize); void draw_title(); void draw_win(WINDOW *new, char *title); @@ -51,6 +52,14 @@ int main(int argc, char **argv){ int prev_height; //used to check if the window was resized int i; + //If passed the quiet flag, disable output + if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))){ + print_help(argv[0]); + return 0; + } + + if(argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) freopen("/dev/null", "w", stdout); + //if a config path was given as an argument, set it accordingly if(argc > 2 && (!strcmp(argv[1], "-c") || !strcmp(argv[1], "--cfg_path"))) strcpy(cfg_path, argv[2]); else strcpy(cfg_path, find_config()); @@ -72,6 +81,9 @@ int main(int argc, char **argv){ //load cached data load_cache(&g_hover, &e_hover, &true_hover, cfg_path); + //reopen stdout for drawing menu + freopen("/dev/tty", "w", stdout); + initscr(); cbreak(); keypad(stdscr, true); @@ -159,6 +171,15 @@ int main(int argc, char **argv){ return 0; } +void print_help(char *exec_name){ + printf("Usage: %s [OPTION] [FILE]\n", exec_name); + printf("Draw an Ncurses Menu to Launch Media from\n\n"); + + printf(" -c, --config Specify a configuration file path\n"); + printf(" -h, --help Print this help message\n"); + printf(" -q, --quiet Suppress stdout messages\n"); +} + void update_display(bool resize){ if(WIDTH < 20 || HEIGHT < 6){ endwin(); -- cgit