terminal: Tmux redraws incorrectly when scrolling

Windows Terminal version

1.15.2875.0

Windows build number

10.0.22621.900

Other Software

tmux 3.3a

Steps to reproduce

I’ve been having this problem since I started using Terminal many month ago. It happens at random, and I’ve never really been able to reproduce it on demand.

  1. Use tmux for while (often days)
  2. Scroll up
  3. See that the scrolling mechanic is messed up

For a while today, I was able to reproduce it this way (but then it stopped reproducing, so I doubt these step will work for anyone)

  1. Start Terminal in WSL with Fedoraremix
  2. Maximize window (doubt this is important)
  3. tmux
  4. docker run -it --rm alpine
  5. find /usr
  6. Scroll up

Expected Behavior

Scrolling to always work correctly, like so:

image

Actual Behavior

You see the numbers in the upper right messed up, and the actual buffer on screen looks all wrong. image

Many more details about the redrawing are incorrect, but this is the simplest to explain

The solution is to close Windows Terminal, and restart it again. Luckily, I’m in tmux so that’s pretty straight forward. But anything less than restarting the tab does not work. Often creating a new tab usaully works and I don’t have to close the entire Windows Terminal window

  • reset does not work
  • Closing tmux and attaching does not work

May be related to #8000 or #6987, but it seemed different enough it might not be.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Right on. Thanks for following up. Glad this got sorted out!

The problem is that tmux introduces another level on indirection, which can make it difficult to reproduce the issue. There are three thing you need to do to trigger the problem:

  1. You need to be in the alt buffer.
  2. You need something to call the SetConsoleMode API.
  3. You need to make use of one the LF, VT, or FF control characters in a way that relies on them moving down without changing the column position.

Just running tmux should satisfy condition 1. And I’m fairly certain wslsys should trigger condition 2. But condition 3 is entirely dependent on how tmux redraws the screen.

In the typescript log that you sent before, I could clearly see it was using an LF from column 96 when it tried to clear the line indicator, and that’s where things went wrong. But when I try to reproduce that on my system, tmux redrew the screen in a completely different way. It only ever used an LF in column 1, so it wasn’t affected by the DISABLE_NEWLINE_AUTO_RETURN mode being wrong.

So if you want to confirm that this is the same problem as #14690, I’d suggest you eliminate tmux from the equation, and try and reproduce my test case from #14690, but see if you can trigger the mode change with docker rather than wslsys.

  1. Switch to the alt buffer with printf "\e[?1049h"
  2. Test the formfeed behavior with printf "\e[10CX\b\fY\n"
  3. Run docker however you normally would
  4. Run the formfeed test again with printf "\e[10CX\b\fY\n"

If docker is triggering the mode change then the output in step 4 should be different from step 2.

This looks to me like it could be a variation of #14690.

When you pan up in the scrollback buffer, this is what tmux does:

  1. Insert a blank line at the top of the screen to move the content down.
  2. Write out the start of the line retrieved from the scrollback, e.g. /usr/bin/comm.
  3. Move forward a few columns with CUF.
  4. Write out a bunch of spaces to pad the line out to column 96 (this is where the line indicator would be rendered).
  5. Move down a line with LF.
  6. Write out some more spaces to erase the old line indicator from before the scroll.
  7. Move back to column 96 in the first row to write the new line indicator.

The problem is that step 5 doesn’t just move down a line, but also moves the cursor back to the first column. So instead of erasing the old line indicator, it’s erasing the start of the line.

And I suspect the reason the LF is behaving incorrectly, is because the DISABLE_NEWLINE_AUTO_RETURN mode has been changed by something. I don’t see wslsys used here, so docker maybe?

Assuming that is the correct interpretation, this should be fixed by PR #14735.