Skip to content

Cursor position incorrect after DECSC, resize with reflow, then DECRC

Issue description

The issue is well described here: https://github.com/ghostty-org/ghostty/issues/5718

There is a bash script reproduction there as well. Additionally, you probably want to reset pending wrap state, and there's a bash script in the first comment of that issue to test that. Beware its easy to fix one and not the other.

This behavior is wholly unspecified, so it's really up to you what you want to do. I'm trying to follow the principle of least surprise for end users and I believe that results in the following behavior (which is what libvte does):

  1. Saved cursors should be reflowed
  2. Pending wrap state should be reset

The reason number 1 is important is detailed in the Ghostty issue, but you can see a real world scenario when entering neovim, resizing the window, exiting neovim, and losing shell text because the restored cursor is put in a place where the shell overwrites prior output.

[!WARNING]

Beware there are two separate "bugs". The bash scripts test two different scenarios, and it's easy to fix one and not the other. Run both!

To Reproduce

There are bash scripts in the linked Ghostty issue, but generally for each script:

  1. Open iTerm2
  2. Resize so its less than half the screen width
  3. Run one of the test scripts
  4. When it pauses, resize the terminal to max size
  5. Press "enter"
  6. Observe the end terminal state