(s)tty: add support for IUTF8 input flag

This patch adds the necessary kernel and stty code to support setting
the IUTF8 flag for ttys. It is the first of two patches that fix
backspace behaviour for UTF-8 encoded characters when in canonical mode.

Reported by:	christos
Reviewed by:	christos, imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D42066
This commit is contained in:
Bojan Novković 2023-10-07 20:59:57 +03:00 committed by Christos Margiolis
parent 662ec2f781
commit 128f63cedc
6 changed files with 11 additions and 2 deletions

View file

@ -126,6 +126,8 @@ static const struct modes imodes[] = {
{ "-decctlq", IXANY, 0 },
{ "imaxbel", IMAXBEL, 0 },
{ "-imaxbel", 0, IMAXBEL },
{ "iutf8", IUTF8, 0 },
{ "-iutf8", 0, IUTF8 },
{ NULL, 0, 0 },
};

View file

@ -127,6 +127,7 @@ print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt)
put("-inpck", INPCK, 0);
put("-ignpar", IGNPAR, 0);
put("-parmrk", PARMRK, 0);
put("-iutf8", IUTF8, 1);
/* output flags */
tmp = tp->c_oflag;

View file

@ -224,6 +224,9 @@ if
.Cm imaxbel
is unset and the input queue is full, the next input character causes
the entire input and output queues to be discarded.
.It Cm iutf8 Pq Fl iutf8
Assume that input characters are UTF-8 encoded. Setting this flag
causes backspace to properly delete multibyte characters in canonical mode.
.El
.Ss Output Modes:
This corresponds to the c_oflag of the termios structure.

View file

@ -884,6 +884,8 @@ following masks:
/* any char will restart after stop */
.It Dv IMAXBEL
/* ring bell on input queue full */
.It Dv IUTF8
/* assume input is UTF-8 encoded */
.El
.Pp
In the context of asynchronous serial data transmission, a break

View file

@ -85,8 +85,8 @@ 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)
#define TTYSUP_IFLAG (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|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|\

View file

@ -97,6 +97,7 @@
#endif
#if __BSD_VISIBLE
#define IMAXBEL 0x00002000 /* ring bell on input queue full */
#define IUTF8 0x00004000 /* assume input is utf-8 encoded */
#endif
/*