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 --- .gitignore | 4 ++-- docs/README.md | 1 + docs/tml.1.gz | Bin 914 -> 961 bytes draw.c | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8c1b636..0f296b8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ !include !include/*.h !unix -!unix/* +!unix/*.c !windows -!windows/* +!windows/*.c diff --git a/docs/README.md b/docs/README.md index d48fd82..5e138ce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -54,4 +54,5 @@ tml -c /path/to/config ``` For Documentation of the configuration file, see [tml-config](tml-config.md). +For a help message and list of flags, `tml --help`. If you installed tml, you can also consult **tml**(1) and **tml-config**(5). diff --git a/docs/tml.1.gz b/docs/tml.1.gz index f93cd14..388d9b8 100644 Binary files a/docs/tml.1.gz and b/docs/tml.1.gz differ 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