Xterm.js: 'restore cursor' restoring position but not text attributes

Created on 20 Jun 2018  路  4Comments  路  Source: xtermjs/xterm.js

I had some issues working with some VT100 escape sequences:

  • save cursor (ESC 7) (DECSC)
  • restore cursor (ESC 8) (DECRC)

Usually, a VT100 terminal should save the cursor position but also characters attributes when writing a save cursor escape sequence
The characters attributes should be restored when writing a restore cursor.

Currently, the position of the cursor is saved and restored but not the characters attributes.

I've tested the behavior of the save/restore escape sequences on other VT100 implementations to ensure they were handling it:

  • gnome-terminal
  • terminator
  • hterm

I'll give some details below, and will start working on a solution since I need it for myself.
Keep up the great work!

Details

  • Browser and browser version: Chromium: Version 62.0.3202.89 (Developer Build) built on Debian buster/sid, running on Debian buster/sid (64-bit)
  • OS version: debian buster/sid
  • xterm.js version: 3.4.1

Steps to reproduce

Here's the VT100 escape sequences used for testing:

\x1b[0m (attributes off)
\x1b[1;1f (reset origin)
\x1b[2J (clear)
\x1b7 (save cursor state)
\x1b[7m (set negative color)
                        <colored> (just some output)
\x1b8 (restore cursor state)
<should not be colored>\n\r (another output - will be printed in negative color in xtermjs)

With xtermjs, "should not be colored" is colored

xterm.write('\x1b[0m\x1b[1;1f\x1b[2J\x1b7\x1b[7m                        <colored>\x1b8<should not be colored>\n\r');
// will print:
// "<should not be colored> <colored>"

In a bash, "should not be colored" won't be colored

printf '\x1b[0m\x1b[1;1f\x1b[2J\x1b7\x1b[7m                        <colored>\x1b8<should not be colored>\n\r'
# will print
# "<should not be colored> <colored>"

How to fix

Seems to me that text attributes should be saved and restored along with the position, here.
Here is how hterm is handling the save/restore cursor

edit:
All the characters attributes (fg color, bg color, and the special flag modes: bold, italic, negative, ..) are stored in the 'curAttr' attribute of the 'Terminal' class. Saving a copy of this attribute should be enough to restore all the characters attributes at once.

help wanted typbug

Most helpful comment

If not we should create a separate issue for it. Capturing all these should probably be done in something like an ICursorState state object to keep things organized.

All 4 comments

VTE used to be buggy too; perhaps you can find a few interesting bits in VTE 731205.

@7PH Since you are modifying DECSC anyways maybe you can have a look at https://vt100.net/docs/vt510-rm/DECSC.html, there are some more terminal attributes still missing, that should be handled as well.

If not we should create a separate issue for it. Capturing all these should probably be done in something like an ICursorState state object to keep things organized.

Merged in the PR and forked off the rest of the properties to https://github.com/xtermjs/xterm.js/issues/1526

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jestapinski picture jestapinski  路  3Comments

Tyriar picture Tyriar  路  4Comments

parisk picture parisk  路  3Comments

LB-J picture LB-J  路  3Comments

Tyriar picture Tyriar  路  4Comments