GNOME Bugzilla – Bug 764088
fullwidth character backspace handled incorrectly in canonical mode + input mode IUTF8
Last modified: 2016-05-08 20:07:44 UTC
Created attachment 324599 [details] [review] a proof-of-concept patch If both of input mode ICANON and local mode IUTF8 are set, "\b" handler incorrectly moves the cursor one cell left when the character on the left is fullwidth.
sorry, it should be "local mode ICANON and int mode IUTF8".
sorry, it should be "local mode ICANON and input mode IUTF8".
Just to be sure we're on the same page, what is your use case that triggers a bug? I assume: You start e.g "cat", enter a CJK character (e.g. Ctrl+Shift+U 4000 Enter), then press backspace and expect the cursor to retreat by 2 positions. Am I right? I don't think it's a bug in vte. A "\b" that is received by vte from the tty driver should always move the cursor back by 1 cell. This is also the behavior of all other terminals. I'm quite certain that the termios settings (e.g. ICANON) should not influence the meaning of an input character in any way. It's a bug (missing feature) in the kernel's tty driver's ICANON mode that it doesn't take width into account, and when pressing a Backspace on the keyboard it erases one cell rather than two. Actually it outputs a "\b \b" (backspace space backspace) to ensure that the cell is visually erased, it should do it twice. The kernel already knows to do this on control characters, e.g. ^E. The kernel also needs to properly track the column (via the width of the characters) to be able to handle TABs, and Backspaces over TABs too. And, of course, combining (zero-width) characters too. Many years ago I sent a few patches to the Linux kernel. Unfortunately I had limited knowledge back then and patched the vt driver instead of the tty layer.
The "cat" example you raised is exactly my use case. I have confirmed that it should be a bug in the erase handler in the kernel's tty driver with the following commands: vte strace -e read,write -p $(pgrep -n vte) |& grep 5 # bash (readline) ~ICANON, two "\b" write(5, "\177", 1) = 1 read(5, "\10\10\33[0m\33[0m \33[0m \10\10", 8176) = 18 ... # cat ICANON, one "\b" write(5, "\177", 1) = 1 read(5, "\10 \10", 8176) = 3 I have a glance at the erase handler in the kernels' tty driver ( https://github.com/torvalds/linux/blob/master/drivers/tty/n_tty.c#L1047 ) and it seems that it does not handle fullwidth backspace in ICANON mode correctly.
I'd love to see this issue fixed! Unfortunately I won't have time to work on it any time soon, nor does the benefit vs. required work ratio look too good. If you make any progress, e.g. report it to the kernel folks, come up with a patch etc., please loop me in, and/or provide a link here, thanks!
I've reported the bug on https://bugzilla.kernel.org/show_bug.cgi?id=115231 . Thank you for your analysis!