zebra

create zebra lines over stdin
git clone git://jb55.com/zebra
Log | Files | Refs | README

commit 8fd29bc1c2e9b7b695d61e0f1329c819f57f74bb
parent ecff068f64c888607101756cc78561bb20893ae6
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 31 Oct 2019 09:07:05 -0700

light bg option

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MREADME | 4++++
Mzebra.c | 25+++++++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/README b/README @@ -11,3 +11,7 @@ Usage $ zebra < file $ ps aux | zebra | less -S + +$ ps aux | zebra --light | less -S + +$ ps aux | zebra --color 128 | less -S diff --git a/zebra.c b/zebra.c @@ -4,10 +4,16 @@ #define streq(a,b) strcmp(a,b) == 0 #define RESET printf("\x1B[0m") +#define DARK "8m" +#define LIGHT "254m" +#define BASE "\x1B[48;5;" void usage() { - printf("usage: zebra [file]\n"); + printf("usage: zebra [OPTION] < file\n\n"); + printf("OPTION\n\n"); + printf(" --light set light background\n"); + printf(" --color 128 set any background color\n\n"); exit(1); } @@ -15,10 +21,25 @@ int main(int argc, const char* argv[]) { int c; int alt = 0; + int light = 0; + char bgcol[32] = {0}; if (argc >= 2 && streq(argv[1], "--help")) { usage(); } + else if (argc >= 2 && streq(argv[1], "--light")) { + light = 1; + } + else if (argc >= 3 && streq(argv[1], "--color")) { + snprintf(bgcol, sizeof(bgcol), BASE "%sm", argv[2]); + } + + if (bgcol[0] == 0) { + if (light) + strcpy(bgcol, BASE LIGHT); + else + strcpy(bgcol, BASE DARK); + } // TODO: files FILE *stream = stdin; @@ -34,7 +55,7 @@ int main(int argc, const char* argv[]) if (c == '\n') { alt ^= 1; if (alt) { - printf("\x1B[48;5;8m"); + printf("%s", bgcol); } else { RESET;