diff --git a/src/main.c b/src/main.c index e8737de..5f8f026 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -174,9 +175,9 @@ main(int argc, char** argv) return 6; } - uint_fast8_t run = 1; + uintmax_t typed_in = 0; - do { + for (;;) { struct epoll_event events[2]; int_fast8_t count = epoll_wait(epoll_fd, events, 2, -1); if (count == -1) { @@ -219,9 +220,33 @@ main(int argc, char** argv) return 9; } - if (chr == '\n') - putchar('\r'); + switch (chr) { + case '\b': + if (!typed_in) + continue; + --typed_in; + putchar('\b'); + putchar(' '); + putchar('\b'); + break; + case '\n': + typed_in = 0; + putchar('\n'); + putchar('\r'); + break; + default: + if (isprint(chr)) { + ++typed_in; + putchar(chr); + } + } + } else { + fputs("ERROR: Event on an untracked file " + "descriptor\n\r", + stderr); + return 10; } + fflush(stdout); } - } while (run); + } }