[PATCH] Fix backspace on wrapped lines in console (virtual terminal)

Previous thread: [PATCH -mm] oprofile: BUG scheduling while atomic by Andrea Righi on Saturday, September 20, 2008 - 9:02 am. (4 messages)

Next thread: alloc_creds ignores gfp arg (MMOTM 2008-09-18-18-08) by Erez Zadok on Saturday, September 20, 2008 - 10:22 am. (1 message)
From: Joe Peterson
Date: Saturday, September 20, 2008 - 9:25 am

Attached is a patch that fixes virtual terminal problems when backspace
is used on wrapped lines (see patch text for the specific issues).  The
issues can be demonstrated by trying two things in the console (vt):

#1

1) issue the "cat" command
2) type characters until you have wrapped cursor to next line
3) hit backspace (nothing happens visually, but char(s) are erased
   in buf, as seen when enter is hit and line is printed to display)

#2

1) issue the "cat" command
2) type characters until you are at the very end of the line
   (cursor now on last char - i.e. in "need_wrap" state)
3) hit backspace (it moves back and visually erases 2nd to last char,
   but hitting enter shows that last char was actually erased in buffer)

							-Joe
From: Alan Cox
Date: Saturday, September 20, 2008 - 9:38 am

On Sat, 20 Sep 2008 10:25:49 -0600

I would need to power up my vt420 to check (yes I have one lurking in a
corner!) but I have a feeling the current behaviour (not going up a line)
is correct for ansi type terminals.

Alan
--

From: Joe Peterson
Date: Saturday, September 20, 2008 - 9:48 am

Would it still erase the actual characters input, though?  This would
cause one to believe they were not erased, since the visual feedback
does not match...  I wonder if "fixing" this in Linux would really break
the needed vt hardware compatibility - maybe that case lies in the
"undefined" area in a sense.

What about the need_wrap (end of line) case - I wonder what the real
vt420 does for that.  If it doesn't match the behavior this patch
"fixes", it would probably be a vt420 bug...

Yes, these things are certainly getting harder to check against real
hardware these days!  :)

						-Joe
--

From: Joe Peterson
Date: Saturday, September 20, 2008 - 4:51 pm

One more thought about this:

xterm has a "private mode 45", which turns on reverseWrap, allowing
backspace to wrap.  This is similar to mode 7 (supported on xterm and
vt), which is DEVAWM (auto wrap mode).

I agree that hard-coding backspace/reverse wrap would likely be wrong
(even though it looks like some terminal emulators I've seen, like
"screen" add the feature), but would it be appropriate to add mode 45 to
vt, allowing reverse wrap as an option?

Also note that vt enables DEVAWM (mode 7) by default, whereas the vt100
docs say that it is off by default.  Since reverse wrap is probably
almost always useful for general Linux in the console, should it also be
on by default if we were to add that option?

						-Joe
--

From: Joe Peterson
Date: Sunday, September 21, 2008 - 9:14 am

I have worked up a new patch (attached) for review.  It adds the private
mode 45 I mentioned above, but defaults it to off, preserving the old
default of no backspace wrap to the previous line.  This matches xterm's
reverse-wrap behavior (and default settings), so the same escape
sequence can be used to control this mode in both xterm and console/vt.

						-Joe
From: Joe Peterson
Date: Tuesday, September 23, 2008 - 1:39 pm

After discussing this with Thomas Dickey (maintainer of xterm), and
running vttest on both xterm and vt, I have generated an even newer
patch for review.  This replaces previous patches in this thread.

xterm only "fixes" the backspace behavior if both reverse wrap and
autowrap modes are enabled.  Although the "fix" is required for accurate
erasure of characters on wrapped lines (and therefore is really nice
when using Linux), the vttest results are not what it expects test 1
(cursor movement).  I do not have a VTxxx to test, but I assume vttest
is true to the hardware.

It makes sense, therefore, to retain the older behavior in vt unless
reverse wrap (which did not exist in the hardware) is enabled.  This
makes the patch true to vttest (and presumably the hardware) as well the
same as xterm in this respect.

							Thanks, Joe

P.S.  If anyone has a VTxxx, it would be interesting to know what
happens with autowrap mode on when backspace is hit after a character is
typed in the rightmost column.  If the cursor moves back, and the 2nd to
last character is then erased, this means the VTxxx behavior will match
the patched vt and xterm (when reverse wrap is not on - i.e. using
standard modes).

Previous thread: [PATCH -mm] oprofile: BUG scheduling while atomic by Andrea Righi on Saturday, September 20, 2008 - 9:02 am. (4 messages)

Next thread: alloc_creds ignores gfp arg (MMOTM 2008-09-18-18-08) by Erez Zadok on Saturday, September 20, 2008 - 10:22 am. (1 message)