Remove useless variable, enable removing only typed characters, change the way inputs are handled

This commit is contained in:
Franck STAUFFER 2020-09-08 23:11:57 +02:00
parent d7521a3b1f
commit fdf8b9a4f5
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261

View File

@ -1,4 +1,5 @@
#include <arpa/inet.h>
#include <ctype.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
@ -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);
}
}