Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353330

Summary: TerminalView does not handle VT100 commands: ^[[M (scroll up) and ^[[D (scroll down)
Product: [Tools] CDT Reporter: Roman Kuzmenko <kuzmenkor>
Component: terminalAssignee: Project Inbox <cdt-core-inbox>
Status: NEW --- QA Contact: Jonah Graham <jonah>
Severity: enhancement    
Priority: P3 CC: aleherb+eclipse, eclipse, jonah
Version: NextFlags: mober.at+eclipse: iplog-
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
a proposed solution
mober.at+eclipse: iplog-
patch converted into Workspace Patch format (v1) none

Description Roman Kuzmenko CLA 2011-07-28 10:42:21 EDT
Build Identifier: M20110213-0444

Index: VT100Emulator.java
===================================================================
RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100
Emulator.java,v
retrieving revision 1.13
diff -u -r1.13 VT100Emulator.java
--- VT100Emulator.java  1 Feb 2009 12:40:23 -0000       1.13
+++ VT100Emulator.java  28 Jul 2011 14:41:14 -0000
@@ -350,6 +350,18 @@
                                        resetTerminal();
                                        break;
 
+                               case 'D':
+                                       // Scroll down
+                                       ansiState = ANSISTATE_INITIAL;
+                                       scrollDown();
+                                       break;
+
+                               case 'M':
+                                       // Scroll up
+                                       ansiState = ANSISTATE_INITIAL;
+                                       scrollUp();
+                                       break;
+
                                default:
                                        Logger
                                                        .log("Unsupported escape sequence: escape '" + character + "'"); //$NON-
NLS-1$ //$NON-NLS-2$
@@ -1049,6 +1061,14 @@
                        return terminal.getTerminalConnector();
                return null;
        }
+       
+       private void scrollDown() {
+               moveCursor(relativeCursorLine() + 1, getCursorColumn());
+       }
+
+       private void scrollUp() {
+               moveCursor(relativeCursorLine() - 1, getCursorColumn());
+       }
 
        /**
         * This method returns the relative line number of the line containing the

Index: VT100EmulatorBackend.java
===================================================================
RCS file: /cvsroot/dsdp/org.eclipse.tm.core/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100
EmulatorBackend.java,v
retrieving revision 1.3
diff -u -r1.3 VT100EmulatorBackend.java
--- VT100EmulatorBackend.java   8 Oct 2007 21:12:56 -0000       1.3
+++ VT100EmulatorBackend.java   28 Jul 2011 14:41:14 -0000
@@ -314,7 +314,9 @@
                        int h=fTerminal.getHeight();
                        fTerminal.addLine();
                        if(h!=fTerminal.getHeight())
-                               setCursorLine(fCursorLine+1);
+                       {
+                               fTerminal.setCursorLine(toAbsoluteLine(fCursorLine));
+                       }
                } else {
                        setCursorLine(fCursorLine+1);
                }
@@ -377,8 +379,21 @@
                synchronized (fTerminal) {
                        if(targetLine<0)
                                targetLine=0;
+                       else if(targetLine == fLines && fCursorColumn == 0)
+                       {
+                               int h=fTerminal.getHeight();
+                               fTerminal.addLine();
+                               
+                               targetLine = fLines - 1;
+                               fCursorLine=targetLine;
+                               
+                               if(h!=fTerminal.getHeight())
+                                       fTerminal.setCursorLine(toAbsoluteLine(targetLine));
+                               return;
+                       }
                        else if(targetLine>=fLines)
                                targetLine=fLines-1;
+
                        fCursorLine=targetLine;
                        // We make the assumption that nobody is changing the
                        // terminal cursor except this class!


Reproducible: Always

Steps to Reproduce:
1. Take an embedded device with an interactive shell which uses the given escape codes to implement multi-line editor.
2. Type in a very long command (more than one line).
3. Check that the second line of your input is displayed on the same line (instead of the next one).
Comment 1 Roman Kuzmenko CLA 2011-07-28 10:45:40 EDT
Created attachment 200534 [details]
a proposed solution
Comment 2 Martin Oberhuber CLA 2011-07-28 10:53:33 EDT
Thanks, we will consider your contribution.

Could you put a statement here on bugzilla indicating that you're authorized by your employer to contribute this under the EPL: See
http://eclipse.org/tm/development/committer_howto.php#external_contrib
Comment 3 Martin Oberhuber CLA 2011-08-04 04:28:51 EDT
(In reply to comment #2)

Roman, can you please put a statement here on bugzilla indicating that you're authorized by your employer to contribute this under the EPL.

I'm afraid I cannot accept the contribution without such a statement.
Comment 4 Roman Kuzmenko CLA 2011-08-31 05:51:05 EDT
(In reply to comment #2)
> Thanks, we will consider your contribution.
> 
> Could you put a statement here on bugzilla indicating that you're authorized by
> your employer to contribute this under the EPL: See
> http://eclipse.org/tm/development/committer_howto.php#external_contrib

I am authorized by my employer to contribute this under EPL.
Comment 5 Martin Oberhuber CLA 2011-09-14 10:49:26 EDT
Created attachment 203343 [details]
patch converted into Workspace Patch format (v1)

Re-attaching the same patch converted into "Workspace Patch format" for easier consumption. Added contributor line.

I think, though, that the implementation of scrollUp() and scrollDown() is incorrect. It seems to just move the cursor, whereas I think it should scroll the visible window (viewport) instead:
http://ascii-table.com/ansi-escape-sequences-vt-100.php

I'm also very concerned about the changes around cursor handling in VT100EmulatorBackend ... I just don't understand what the new code is supposed to do or fix, and this is a sensitive area where we've had issues in the past.

Please revise the patch or explain what it does. Ideally, also test against a couple of ANSI sequences to validate it's working as expected (points 11-14 here: http://www.columbia.edu/kermit/vttest.html )
Comment 6 Martin Oberhuber CLA 2011-09-14 10:57:45 EDT
Also, note that for an ANSI compatible terminal (which the Eclipse Terminal is), the correct sequence for scrolling is CSI n S / CSI n T -- not yet implemented, but prepared in VT100Emulator line 511 / line 517.

http://en.wikipedia.org/wiki/ANSI_escape_code

I'm marking this as an enhancement request since our Terminal does ANSI and not vt100. Can you try eg "setenv TERM ansi" on your embedded terminal?
Comment 7 Martin Oberhuber CLA 2015-05-22 12:40:37 EDT
Comment on attachment 200534 [details]
a proposed solution

I'm marking the proposed patch obsolete since as per my comment 5 I think the implementation of scrollUp() and scrollDown() is incorrect.

Also, now that we have Terminal 4.0 with some xterm support, I'm not sure how relevant the support for scrollUp and scrollDown actually is. I think I've seen those codes used by some programs in the past, but haven't seen any issues recently.
Comment 8 Jonah Graham CLA 2020-05-01 10:09:06 EDT
The Terminal component of the Eclipse Ecosystem has a new home. The Terminal is now part of the Eclipse CDT project[1].

This change means a new Git repo[2], P2 site[3] and Bugzilla component. The terminal will continue to be delivered as part of the quarterly Simultaneous Release of Eclipse as well.

The marketplace entry[4] had not been updated in a few years. It will once again install the latest release of the terminal on the latest release of the whole IDE (currently 2020-03).

If this bug is no longer relevant, please feel free to comment or close the bug. If you can confirm if this issues still occurs in the latest release please do let me know in a comment.

[1] https://wiki.eclipse.org/CDT/User/NewIn911
[2] https://git.eclipse.org/c/cdt/org.eclipse.cdt.git (in the terminal directory)
[3] current release is 9.11 - P2 site https://download.eclipse.org/tools/cdt/releases/9.11/
[4] https://marketplace.eclipse.org/content/tm-terminal

(This comment was added to all open terminal bugs along with changing the Product/component pair to CDT/terminal.)
Comment 9 Jonah Graham CLA 2020-05-11 11:54:08 EDT
I have come across this problem with current version of the terminal and the default TERM to xterm. The result is that "less" in Ubuntu 18.04 does not scroll up properly because we don't interpret \eM:

VT100Emulator.processNewText:484: Unsupported escape sequence: escape 'M'

Changing to TERM=ansi fixes the scroll, but then other functionality, such as PgUp/PgDn stops working.