X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=mdp.c;h=4fe4a63907f3a87671418eb251842e41a8762660;hb=02de567610f7c582e5618e75970b40e4802b005e;hp=9a71cd0fd569c51362b8084c444957c4e2985353;hpb=d4843ea375360f37e965709e73c0fbd68e302dca;p=smdp.git diff --git a/mdp.c b/mdp.c index 9a71cd0..4fe4a63 100644 --- a/mdp.c +++ b/mdp.c @@ -32,13 +32,14 @@ void usage() { fprintf(stderr, "%s", " add it multiple times to increases debug level\n"); fprintf(stderr, "%s", " -f, --nofade disable color fading in 256 color mode\n"); fprintf(stderr, "%s", " -h, --help display this help and exit\n"); + fprintf(stderr, "%s", " -i, --invert swap black and white color\n"); fprintf(stderr, "%s", " -t, --notrans disable transparency in transparent terminal\n"); fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n"); exit(EXIT_FAILURE); } void version() { - printf("mdp %d.%d\n", MAJOR_VERSION, MINOR_VERSION); + printf("mdp %d.%d.%d\n", MDP_VER_MAJOR, MDP_VER_MINOR, MDP_VER_REVISION); printf("Copyright (C) 2014 Michael Goehler\n"); printf("License GPLv3+: GNU GPL version 3 or later .\n"); printf("This is free software: you are free to change and redistribute it.\n"); @@ -50,12 +51,14 @@ void version() { int main(int argc, char *argv[]) { int notrans = 0; int nofade = 0; + int invert = 0; // define command-line options struct option longopts[] = { { "debug", no_argument, 0, 'd' }, { "nofade", no_argument, 0, 'f' }, { "help", no_argument, 0, 'h' }, + { "invert", no_argument, 0, 'i' }, { "notrans", no_argument, 0, 't' }, { "version", no_argument, 0, 'v' }, { 0, 0, 0, 0 } @@ -63,11 +66,12 @@ int main(int argc, char *argv[]) { // parse command-line options int opt, debug = 0; - while ((opt = getopt_long(argc, argv, ":dfhtv", longopts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, ":dfhitv", longopts, NULL)) != -1) { switch(opt) { case 'd': debug += 1; break; case 'f': nofade = 1; break; case 'h': usage(); break; + case 'i': invert = 1; break; case 't': notrans = 1; break; case 'v': version(); break; case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break; @@ -104,11 +108,20 @@ int main(int argc, char *argv[]) { // close file fclose(input); + // replace stdin with current tty if input was a pipe + if(input == stdin) { + input = freopen("/dev/tty", "rw", stdin); + if(!input) { + fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno)); + exit(EXIT_FAILURE); + } + } + if(debug > 0) { markdown_debug(deck, debug); } - ncurses_display(deck, notrans, nofade); + ncurses_display(deck, notrans, nofade, invert); return(EXIT_SUCCESS); }