aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBojan Novković <bojan.novkovic@fer.hr>2023-10-07 17:59:57 +0000
committerChristos Margiolis <christos@FreeBSD.org>2023-10-07 17:59:57 +0000
commit128f63cedc14ae21b35f74e11e2fe1a5659c58e8 (patch)
treeefac586e64de71c28aae61ee4b155267e32cdac7
parent662ec2f781521c36b76af748d74bb0a3c2e27a76 (diff)
downloadsrc-128f63cedc14ae21b35f74e11e2fe1a5659c58e8.tar.gz
src-128f63cedc14ae21b35f74e11e2fe1a5659c58e8.zip
(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
-rw-r--r--bin/stty/modes.c2
-rw-r--r--bin/stty/print.c1
-rw-r--r--bin/stty/stty.13
-rw-r--r--share/man/man4/termios.42
-rw-r--r--sys/kern/tty.c4
-rw-r--r--sys/sys/_termios.h1
6 files changed, 11 insertions, 2 deletions
diff --git a/bin/stty/modes.c b/bin/stty/modes.c
index ce39083d7d63..3818677ddc4e 100644
--- a/bin/stty/modes.c
+++ b/bin/stty/modes.c
@@ -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 },
};
diff --git a/bin/stty/print.c b/bin/stty/print.c
index 07a3c2058474..33472bbccea1 100644
--- a/bin/stty/print.c
+++ b/bin/stty/print.c
@@ -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;
diff --git a/bin/stty/stty.1 b/bin/stty/stty.1
index 9e9405928c67..c572a657a997 100644
--- a/bin/stty/stty.1
+++ b/bin/stty/stty.1
@@ -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.
diff --git a/share/man/man4/termios.4 b/share/man/man4/termios.4
index d3a5c8fa582d..80015025345e 100644
--- a/share/man/man4/termios.4
+++ b/share/man/man4/termios.4
@@ -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
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 134c1dfba98b..620233947410 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -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|\
diff --git a/sys/sys/_termios.h b/sys/sys/_termios.h
index 327ffcb2f98b..823752732ee2 100644
--- a/sys/sys/_termios.h
+++ b/sys/sys/_termios.h
@@ -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
/*