eel

formatter for ii(1) logs
Log | Files | Refs | README

commit b45750de7236dd40c0a76fdf4ebab9a7f25faca3
parent 7f0848466bec45d525e5a8e183e95072b225ad2c
Author: Josuah Demangeon <mail@josuah.net>
Date:   Wed,  6 Jun 2018 04:22:50 +0200

basically works, need polishing and more features

Diffstat:
Mmplex.c | 23++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/mplex.c b/mplex.c @@ -14,7 +14,7 @@ #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define LEN(x) (sizeof(x) / sizeof(*(x))) -static struct termios termios; +static struct termios termios; /* ** Take terminal out of raw mode. @@ -121,15 +121,13 @@ display_line(void) { int c; - while ((c = fgetc(stdin)) != '\n') { - if (c == EOF) { - if (ferror(stdin)) - perror("fgetc stdin"), exit(1); - exit(0); - } + fputs("\r\033[K", stderr); + do { + if ((c = fgetc(stdin)) == EOF) + die("fgetc stdin"); if (fputc(c, stderr) == -1) perror("fputc tty"), exit(1); - } + } while (c !='\n'); if (fflush(stderr) == -1) perror("fflush tty"); } @@ -153,9 +151,9 @@ main(int argc, char **argv) prompt = (argc == 2) ? argv[1] : "> "; if (isatty(STDIN_FILENO)) - return fputs("stdin should not be a tty\n", stderr), -1; + return fputs("stdin should not be a tty\n", stderr), 1; if (!isatty(STDERR_FILENO)) - return fputs("stderr should be a tyy\n", stderr), -1; + return fputs("stderr should be a tyy\n", stderr), 1; set_terminal(); @@ -171,16 +169,15 @@ main(int argc, char **argv) if (poll(pfd, 2, -1) == -1) die("poll"); - if ((pfd[0].revents | pfd[1].revents) & POLLHUP) - break; if (pfd[0].revents & POLLIN) display_line(); + if ((pfd[0].revents | pfd[1].revents) & POLLHUP) + break; if (pfd[1].revents & POLLIN) if ((pos = get_input(input, pos, sizeof(input))) == -1) break; } fputc('\n', stderr); - reset_terminal(); return 0;