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

Bug 401386

Summary: [terminal] Regression: No header when running "top" in Terminal, due to incorrect ESC[K handling
Product: [Tools] Target Management Reporter: Anna Dushistova <anna.dushistova>
Component: TerminalAssignee: Martin Oberhuber <mober.at+eclipse>
Status: RESOLVED FIXED QA Contact: Martin Oberhuber <mober.at+eclipse>
Severity: major    
Priority: P2 CC: chris, eclipse, eliasbalasis, ruud
Version: 3.4.2   
Target Milestone: 3.5 M6   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Bug Depends on: 392107    
Bug Blocks: 404341    
Attachments:
Description Flags
screenshot
none
Log none

Description Anna Dushistova CLA 2013-02-21 01:36:14 EST
Tested with TCF terminals view and standalone terminal, tcf and ssh connections.
The header is now missing completely. It's Eclipse 4.2.1 on OpenSuse 12.1.
Seems to be a regression to me, used to show the output properly.
Comment 1 Martin Oberhuber CLA 2013-02-21 04:46:06 EST
Try using the TM Terminal (not TE variant), using ssh, and echo $TERM in your terminal - it should be "ansi". For me, top runs just fine in a Juno SR1 TM-Terminal over ssh to OpenSuSE 12.2:

   09 mober@szg-vm01-opensuse-12~>cat /etc/SuSE-release 
   openSUSE 12.2 (x86_64)
   VERSION = 12.2
   CODENAME = Mantis
   110 mober@szg-vm01-opensuse-12~>echo $TERM
   ansi

I can even resize the terminal at will and top keeps happy. My host was a RHEL 6.3 (Santiago) 64-bit machine running a 32-bit JVM.

   1178 mober@szg-qa-lx5/$rpm -qa | grep -i gtk
   [some stuff stripped]
   gtk2-engines-2.18.4-5.el6.x86_64
   gtk2-2.18.9-10.el6.x86_64
   gtk2-2.18.9-10.el6.i686
   gtk2-engines-2.18.4-5.el6.i686
Comment 2 Anna Dushistova CLA 2013-02-21 11:34:18 EST
(In reply to comment #1)
> Try using the TM Terminal (not TE variant), using ssh, and echo $TERM in
> your terminal - it should be "ansi".

It is "ansi". I am using java 1.7.0-06 if that matters, 32 bit. Tried opening a terminal onto both my localhost and a qemu target running yocto sato image.
Comment 3 Martin Oberhuber CLA 2013-02-21 12:06:06 EST
Can you create folder /tmp/eclipselogs as per bug 209665 comment 4 .

Try again via TM-Terminal/ssh, then attach a screenshot showing the problem as well as the file /tmp/eclipselogs/tmterminal.log -- let's see whether your remote sends any unexpected escape chars.

And of course, trying on top of Eclipse 3.8.1 / Oracle Java 1.6.0_21 32-bit might make sense when you want to replicate my environment.
Comment 4 Anna Dushistova CLA 2013-02-21 14:32:32 EST
Created attachment 227416 [details]
screenshot
Comment 5 Anna Dushistova CLA 2013-02-21 14:33:33 EST
Created attachment 227417 [details]
Log
Comment 6 Anna Dushistova CLA 2013-02-21 14:34:37 EST
Screenshot was taken for the tcf terminal, but ssh one looks exactly the same.The header is missing.
Comment 7 Martin Oberhuber CLA 2013-02-21 15:46:12 EST
The interesting thing here is that the Terminal does leave some empty space where the header is supposed to be. That prompts me to assume that the contents is there, but you might have a problem with colors or fonts; or some ANSI sequence like "delete-to-end-of-line" is not interpreted properly.

In the log, the header is received but then I see this:
VT100Emulator.processAnsiCommand_m:834: Unsupported graphics rendition parameter: 39
VT100Emulator.processAnsiCommand_m:834: Unsupported graphics rendition parameter: 49

This quite apparently refers to this escape sequence:
\x1b[39;49m

According to http://en.wikipedia.org/wiki/Ansi_terminal this is an SGR command saying "set default text color ; default background color" which, according to the standard again, has "implementation defined" effect. The current terminal widget doesn't interpret these codes at the moment, though adding these would likely be very easy (VT100Emulator.java line 799).

But the bigger problem here is likely the
\x1b[K
Which your "top" sends at the end of each line. According to the standard, it's meant to "erase to end of line". I believe that you're actually seeing 
bug 392107 here -- older versions of the Terminal interpreted this as "erase to beginning of line" which clears your output.

Please make sure that you have the Terminal widget 3.4.2 or later, then try again. In my working install, I have
     org.eclipse.tm.terminal_3.2.1.201209191030.jar
what do you have ?
Comment 8 Martin Oberhuber CLA 2013-02-21 16:34:40 EST
Double checking again with master, I have to confirm that you did in fact find a regression due to the fix for bug 392107 .

The problem is, that in the sequence
    ESC [ K
the missing parameter is interpreted as a default value of 1, but the standard says that the default must be 0 here. Before the fix for bug 392107, the invalid default value resulted in correct behavior, since the interpretation of values 0 and 1 was switched.
Comment 9 Martin Oberhuber CLA 2013-02-21 17:03:26 EST
Fixed in master.

Given that this was a regression between 3.4.1 and 3.4.2 (Juno SR1 -> SR2), I think that the fix should be backported into 3.4.2+ .
Comment 10 Martin Oberhuber CLA 2013-02-21 17:17:40 EST
CQ:WIND00must_fix

Marking P2 / critical since in most real-world scenarios that do a little bit of Terminal handling (top, emacs, vi, ...) the terminal is likely quite unusable due to this bug. It's really surprising that the bug went unnoticed for so long. Looks like we don't test our Nightlies enough.
Comment 12 Martin Oberhuber CLA 2013-03-26 05:25:46 EDT
*** Bug 404250 has been marked as a duplicate of this bug. ***
Comment 13 Martin Oberhuber CLA 2013-03-27 11:00:24 EDT
Workaround for anyone running into this issue in TM 3.4.2 (Juno SR2):

Try Help > Install New Software:
   http://download.eclipse.org/tm/updates/3.5milestones
and pick the TM Terminal.

We are working on a TM 3.4.3 release on the main TM update site, such that "Help > Check for Updates" will pull in the fix. This is tracked in bug 404341 .
Comment 14 Martin Oberhuber CLA 2013-03-27 11:01:30 EDT
*** Bug 404439 has been marked as a duplicate of this bug. ***
Comment 15 Martin Oberhuber CLA 2013-04-03 07:35:55 EDT
*** Bug 404787 has been marked as a duplicate of this bug. ***