diff --git a/README.md b/README.md index 0c66f29..8a23cdb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,15 @@ A lightweight bar based on XCB (yay). Provides foreground/background color switching along with text alignment (screw you dzen!), nothing less and nothing more. +Options +------- +bar accpets a couple of command line switches + +``` +-h Shows the help and bails out. +-p Make the bar permanent. +``` + Configuration ------------- Change the config.h file and you're good to go! diff --git a/bar.c b/bar.c index e151a4f..a9304e7 100644 --- a/bar.c +++ b/bar.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -52,7 +51,7 @@ draw (int x, int align, char *text) void parse (char *text) { - char parsed_text[1000] = {0, }; + char parsed_text[1024] = {0, }; char *p = text; char *q = parsed_text; @@ -143,26 +142,31 @@ init (void) } int -main (void) +main (int argc, char **argv) { - struct pollfd stdinpoll = { .fd = 0, .events = POLLIN | POLLHUP }; - static char input[1000] = {0, }; + static char input[1024] = {0, }; + int permanent = 0; + char ch; + + while ((ch = getopt (argc, argv, "ph")) != -1) { + switch (ch) { + case 'h': + printf ("usage: %s [-p | -h]\n\t-h Shows this help\n\t-p Don't close after the data ends\n", argv[0]); exit (0); + case 'p': permanent = 1; break; + } + } atexit (cleanup); signal (SIGINT, sighandle); signal (SIGTERM, sighandle); init (); - for (;;) { - if (poll (&stdinpoll, 1, -1) > 0) { - if (stdinpoll.revents & POLLHUP) break; - if (stdinpoll.revents & POLLIN) { - fgets (input, sizeof(input), stdin); - parse (input); - xcb_flush (c); - } - } + while (fgets (input, sizeof(input), stdin)) { + parse (input); + xcb_flush (c); } + /* There's no more data, but the user still wants to see it */ + while (permanent); return 0; }