More correct handling of VINTR/VEOF

This commit is contained in:
Mark
2020-07-01 17:51:42 +03:00
parent 5e96775826
commit 6f428c8343
3 changed files with 80 additions and 67 deletions
+14 -1
View File
@@ -15,21 +15,33 @@
#define ONLRET (1 << 6)
// Control flags
#define ISIG (1 << 0)
#define ECHO (1 << 4) // Echo input characters
#define ECHOE (1 << 5) // if ICANON, ERASE erases prec. character,
// WERASE erases prec. word
#define ECHOK (1 << 6) // if ICANON, KILL character erases the line
#define ECHONL (1 << 8) // if ICANON, echo newline (even if no ECHO)
enum {
VEOF = 0,
VINTR,
NCCS
};
#define TERMIOS_DEFAULT \
{ \
.c_iflag = ICANON, \
.c_oflag = OPOST, \
.c_cflag = 0, \
.c_lflag = ECHO | ECHONL | ECHOE | ECHOK, \
.c_lflag = ECHO | ECHONL | ECHOE | ECHOK | ISIG, \
.c_cc = { \
[VEOF] = 4, \
[VINTR] = 3, \
}, \
}
typedef unsigned int tcflag_t;
typedef char cc_t;
struct winsize {
unsigned short ws_row;
@@ -43,6 +55,7 @@ struct termios {
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_cc[NCCS];
};
#define TCSANOW 0
+48 -45
View File
@@ -7,43 +7,43 @@
struct console *g_keyboard_console = NULL;
void input_scan(uint8_t c) {
//switch (c) {
//case INPUT_KEY_UP:
// tty_data_write(g_keyboard_tty, '\033');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, 'A');
// break;
//case INPUT_KEY_DOWN:
// tty_data_write(g_keyboard_tty, '\033');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, 'B');
// break;
//case INPUT_KEY_RIGHT:
// tty_data_write(g_keyboard_tty, '\033');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, 'C');
// break;
//case INPUT_KEY_LEFT:
// tty_data_write(g_keyboard_tty, '\033');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, 'D');
// break;
//case INPUT_KEY_HOME:
// tty_data_write(g_keyboard_tty, '\033');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, 'H');
// break;
//case INPUT_KEY_END:
// tty_data_write(g_keyboard_tty, '\033');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, '[');
// tty_data_write(g_keyboard_tty, 'F');
// break;
//default:
// kdebug("Ignoring unhandled key: %02x\n", c);
// break;
//}
switch (c) {
case INPUT_KEY_UP:
console_type(g_keyboard_console, '\033');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, 'A');
break;
case INPUT_KEY_DOWN:
console_type(g_keyboard_console, '\033');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, 'B');
break;
case INPUT_KEY_RIGHT:
console_type(g_keyboard_console, '\033');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, 'C');
break;
case INPUT_KEY_LEFT:
console_type(g_keyboard_console, '\033');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, 'D');
break;
case INPUT_KEY_HOME:
console_type(g_keyboard_console, '\033');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, 'H');
break;
case INPUT_KEY_END:
console_type(g_keyboard_console, '\033');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, '[');
console_type(g_keyboard_console, 'F');
break;
default:
kdebug("Ignoring unhandled key: %02x\n", c);
break;
}
}
void input_key(uint8_t key, uint8_t mods, const char *map0, const char *map1) {
@@ -71,14 +71,17 @@ void input_key(uint8_t key, uint8_t mods, const char *map0, const char *map1) {
input_scan(c);
}
} else {
//char c = map0[key];
char c = map0[key];
//switch (c) {
//case 'c':
//case '.':
//case 'd':
// tty_control_write(g_keyboard_tty, c);
// break;
//}
switch (c) {
case 'd':
console_type(g_keyboard_console, 4); // EOT
break;
case 'c':
console_type(g_keyboard_console, 3); // ETX
break;
default:
break;
}
}
}
+18 -21
View File
@@ -27,29 +27,26 @@ static int tty_ioctl(struct chrdev *tty, unsigned int cmd, void *arg);
static const struct termios default_termios = TERMIOS_DEFAULT;
//void tty_control_write(struct chrdev *tty, char c) {
// struct tty_data *data = tty->dev_data;
// _assert(data);
//
// switch (c) {
// case 'd':
// ring_signal(&tty->buffer, RING_SIGNAL_EOF);
// break;
// case '.':
// //ring_signal(&tty->buffer, RING_SIGNAL_BRK);
// thread_signal_pgid(data->fg_pgid, SIGUSR1);
// break;
// case 'c':
// //ring_signal(&tty->buffer, RING_SIGNAL_BRK);
// thread_signal_pgid(data->fg_pgid, SIGINT);
// break;
// default:
// panic("Unhandled control to TTY: ^%c\n", c);
// }
//}
void tty_data_write(struct chrdev *tty, char c) {
_assert(tty && tty->type == CHRDEV_TTY);
if ((tty->tc.c_iflag & ICANON) && (tty->tc.c_cc[VEOF] == c)) {
// EOF
ring_signal(&tty->buffer, RING_SIGNAL_EOF);
return;
}
if (tty->tc.c_cc[VINTR] == c) {
if (tty->tc.c_lflag & ISIG) {
thread_signal_pgid(((struct tty_data *) tty->dev_data)->fg_pgid, SIGINT);
return;
} else {
// Just display ^C
tty_putc(tty, '^');
tty_putc(tty, 'C');
}
}
ring_putc(NULL, &tty->buffer, c, 0);
switch (c) {