1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:57:34 +00:00

Terminal: Support VKILL and VERASE. Also ignore null characters.

This commit is contained in:
Andreas Kling 2019-01-25 15:34:21 +01:00
parent d059e684a2
commit 92c14ba887

View file

@ -19,6 +19,7 @@ struct GlobalState {
char hostname[32]; char hostname[32];
pid_t sid; pid_t sid;
uid_t uid; uid_t uid;
termios termios;
}; };
static GlobalState* g; static GlobalState* g;
@ -364,6 +365,8 @@ int main(int, char**)
g->sid = setsid(); g->sid = setsid();
tcsetpgrp(0, getpgrp()); tcsetpgrp(0, getpgrp());
tcgetattr(0, &g->termios);
{ {
struct sigaction sa; struct sigaction sa;
sa.sa_handler = handle_sigint; sa.sa_handler = handle_sigint;
@ -414,11 +417,22 @@ int main(int, char**)
} }
for (ssize_t i = 0; i < nread; ++i) { for (ssize_t i = 0; i < nread; ++i) {
char ch = keybuf[i]; char ch = keybuf[i];
if (ch == 8) { if (ch == 0)
continue;
if (ch == 8 || ch == g->termios.c_cc[VERASE]) {
if (linedx == 0) if (linedx == 0)
continue; continue;
linebuf[--linedx] = '\0'; linebuf[--linedx] = '\0';
putchar(ch); putchar(8);
fflush(stdout);
continue;
}
if (ch == g->termios.c_cc[VKILL]) {
if (linedx == 0)
continue;
for (; linedx; --linedx)
putchar(0x8);
linebuf[0] = '\0';
fflush(stdout); fflush(stdout);
continue; continue;
} }