zebra

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

commit ecff068f64c888607101756cc78561bb20893ae6
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 31 Oct 2019 08:48:08 -0700

initial commit

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

Diffstat:
A.gitignore | 1+
AMakefile | 3+++
AREADME | 13+++++++++++++
Azebra.c | 46++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +/zebra diff --git a/Makefile b/Makefile @@ -0,0 +1,3 @@ + +zebra: zebra.c + $(CC) $< -o $@ diff --git a/README b/README @@ -0,0 +1,13 @@ + +zebra +===== + +Add zebra lines from stdin to stdout + + +Usage +----- + +$ zebra < file + +$ ps aux | zebra | less -S diff --git a/zebra.c b/zebra.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#define streq(a,b) strcmp(a,b) == 0 +#define RESET printf("\x1B[0m") + +void usage() +{ + printf("usage: zebra [file]\n"); + exit(1); +} + +int main(int argc, const char* argv[]) +{ + int c; + int alt = 0; + + if (argc >= 2 && streq(argv[1], "--help")) { + usage(); + } + + // TODO: files + FILE *stream = stdin; + + while (1) { + c = getc(stream); + + if (c == EOF) + break; + + putc(c, stdout); + + if (c == '\n') { + alt ^= 1; + if (alt) { + printf("\x1B[48;5;8m"); + } + else { + RESET; + } + } + } + + RESET; +}