diff --git a/bin/stty/modes.c b/bin/stty/modes.c index 0fe4e5168d2c..30990c578637 100644 --- a/bin/stty/modes.c +++ b/bin/stty/modes.c @@ -129,6 +129,8 @@ static const struct modes imodes[] = { { "-decctlq", IXANY, 0 }, { "imaxbel", IMAXBEL, 0 }, { "-imaxbel", 0, IMAXBEL }, + { "iutf8", IUTF8, 0 }, + { "-iutf8", 0, IUTF8 }, { NULL, 0, 0 }, }; diff --git a/bin/stty/stty.1 b/bin/stty/stty.1 index 1863c2286176..0b4efbf802b6 100644 --- a/bin/stty/stty.1 +++ b/bin/stty/stty.1 @@ -211,6 +211,8 @@ empty/full. Allow any character (allow only .Dv START ) to restart output. +.It Cm iutf8 Pq Fl iutf8 +Erase multibyte UTF-8 letters. .It Cm imaxbel Pq Fl imaxbel The system imposes a limit of .Dv MAX_INPUT diff --git a/share/man/man4/termios.4 b/share/man/man4/termios.4 index 9478c87c158f..7f32f586345e 100644 --- a/share/man/man4/termios.4 +++ b/share/man/man4/termios.4 @@ -876,6 +876,8 @@ following masks: /* enable input flow control */ .It Dv IXANY /* any char will restart after stop */ +.It Dv IUTF8 +/* make ERASE character remove UTF-8 multibyte letters */ .It Dv IMAXBEL /* ring bell on input queue full */ .El @@ -1052,6 +1054,15 @@ and characters are transmitted are implementation defined. .Pp If +.Dv IUTF8 +and +.Dv ICANON +are set, +every letter would be removed as a UTF-8 multibyte letter upon receipt of the +.Dv ERASE +character. +.Pp +If .Dv IMAXBEL is set and the input queue is full, subsequent input shall cause an .Tn ASCII diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 4c11ff56000b..1f75214cbf42 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -86,7 +86,7 @@ static const char *dev_console_filename; * Flags that are supported and stored by this implementation. */ #define TTYSUP_IFLAG (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|\ - INLCR|IGNCR|ICRNL|IXON|IXOFF|IXANY|IMAXBEL) + INLCR|IGNCR|ICRNL|IXON|IXOFF|IXANY|IMAXBEL|IUTF8) #define TTYSUP_OFLAG (OPOST|ONLCR|TAB3|ONOEOT|OCRNL|ONOCR|ONLRET) #define TTYSUP_LFLAG (ECHOKE|ECHOE|ECHOK|ECHO|ECHONL|ECHOPRT|\ ECHOCTL|ISIG|ICANON|ALTWERASE|IEXTEN|TOSTOP|\ diff --git a/sys/kern/tty_ttydisc.c b/sys/kern/tty_ttydisc.c index 0e3c785545a1..adb7db4da0a8 100644 --- a/sys/kern/tty_ttydisc.c +++ b/sys/kern/tty_ttydisc.c @@ -737,9 +737,16 @@ ttydisc_rubchar(struct tty *tp) int quote; unsigned int prevpos, tablen; - if (ttyinq_peekchar(&tp->t_inq, &c, "e) != 0) - return (-1); - ttyinq_unputchar(&tp->t_inq); +#define MULTIBYTE(u) (((u) & 0x80) == 0x80) +#define FIRST_OCTET(u) (((u) & 0xC0) == 0xC0) + bool utf8 = CMP_FLAG(i, IUTF8); + do { + if (ttyinq_peekchar(&tp->t_inq, &c, "e) != 0) + return (-1); + ttyinq_unputchar(&tp->t_inq); + } while(utf8 && MULTIBYTE(c) && !FIRST_OCTET(c)); +#undef MULTIBYTE +#undef FIRST_OCTET if (CMP_FLAG(l, ECHO)) { /* diff --git a/sys/sys/_termios.h b/sys/sys/_termios.h index fab12cfa4064..b1970430d289 100644 --- a/sys/sys/_termios.h +++ b/sys/sys/_termios.h @@ -98,6 +98,7 @@ #endif #if __BSD_VISIBLE #define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#define IUTF8 0x00004000 /* support UTF-8 encoding */ #endif /*