zellij icon indicating copy to clipboard operation
zellij copied to clipboard

ANSI control codes corrupt view

Open Hylian opened this issue 1 year ago • 7 comments

Basic information

zellij --version: zellij 0.40.1

stty size: 53 234

uname -av or ver(Windows): Debian 6.6.15

Further information

The output sequence attached causes the zellij output to become corrupt, preventing scrolling and drawing over adjacent panes. This behavior is not observed outside zellij, when running in the foot termemu.

I don't think this is the absolute minimal repro, but the second line being long enough to wrap seems to be important for triggering this bug.

Reproduction Steps

  • Open new zellij window
  • /usr/bin/cat zellij_test.log
  • Observe unable to scroll pane without resizing pane first
  • Observe new output is constrained to bottom row
  • Open new zellij window (reset)
  • Open two panes, vertically tiled
  • /usr/bin/cat zellij_test.log in top pane
  • Observe pane output spills into the pane below

zellij_test.log

zellij.log

zellij-14.log

Hylian avatar Jul 10 '24 18:07 Hylian

Hey @Hylian - thanks for the excellent reproduction!

I couldn't 100% reproduced what you mentioned, I think it might be because the provided stty size is not the same size as the terminal pane in which the reproduction was run. With some guesswork however, I managed to find what I think is the issue.

I minimized the reproduction down to the following ANSI sequence: echo -e "\033[1;42r\033[42;1HHi there!" when run in a pane with less than 42 lines. I issues a fix for this: https://github.com/zellij-org/zellij/pull/3491 - which I'll merge once the CI is happy.

Would you like to give this a test, see if this was the issue you were experiencing or if there's something else involved?

imsnif avatar Jul 12 '24 10:07 imsnif

Observe new output is constrained to bottom row

Just a note though about this: this is probably by design and is what happens when the scroll region is set to be smaller than the terminal pane size (some older applications use this for scrolling parts of the screen, eg. vim).

imsnif avatar Jul 12 '24 10:07 imsnif

Thanks for the quick fix! I cherry-picked on v0.40.1, and the test file no longer spills into the pane below or breaks scrolling!

Unfortunately, the output from my build system is still causing issues. Previously, scrolling would break halfway through the build (which is where I grabbed the repro), and this seems to be fixed! But there is some output the end of the build that is still breaking things. The incorrect lines of the intermediate build output are erased, and the same scroll 'lock' behavior is observed. When I pipe to less, the build output is displayed properly. I'll see if I can grab a repro of this one as well.

Just a note though about this: this is probably by design and is what happens when the scroll region is set to be smaller than the terminal pane size (some older applications use this for scrolling parts of the screen, eg. vim).

Oh, interesting, I didn't know about this! That explains why I was seeing different behavior replaying stdout at different pane sizes. Seems like I'm learning a lot about terminal emulators this week :)

Hylian avatar Jul 12 '24 20:07 Hylian

zellij_test_2.log

Here's the new repro, and it does seem to be related to scroll region.

Seems like what's happening is:

  • Line 1: setup scrolling region
  • Lines 2-11: Final output from the build that should stay on screen
  • Line 12: One of the build threads comes back and prints its intermediate output, realizes the build has ended, and moves the cursor around to delete the lines it printed.
  • Line 13: More final build output
  • Lines 16-17: Resets scrolling region

Observed behavior:

  • Lines 2-11 should remain on screen, but are missing
  • Scrolling breaks starting from line 13

stty size: 63 280

Hylian avatar Jul 12 '24 21:07 Hylian

Hey @Hylian - I'm unfortunately not reproducing this issue with the script (or maybe I didn't understand it properly). When I cat it to screen in a zellij pane with 63 rows and 280 columns, this is what I see on screen: img-2024-07-19-131934.

I see the same thing on screen outside of Zellij (in Alacritty). What am I missing?

Also, could you please include reproductions with a much smaller screen size (eg. 43/234)? My screen is not so big and I have to decrease the font size considerably to make this out. :) Thanks!

imsnif avatar Jul 19 '24 11:07 imsnif

The main issue is that the lines higher up in the file ("this text should appear but doesn't") should also be printed, but don't. The context is that the build system has standard scrolling output for most of the screen, but redraws the bottom few lines with compilation statusbars. When the compilation errors out, it prints the final error status, but some build threads join late and print to stdout. Normally, that thread cleans up after itself, but in zellij, it clobbers other output instead. Scrolling also breaks in a manner similar to my original issue repro.

I'll try and get a repro on a smaller tty size when I can. It involves using tail and head to essentially bisect build output that's over 10kB large, so it's not the easiest to capture. :P

Hylian avatar Jul 19 '24 17:07 Hylian

I hear ya, these reproductions - even when they don't need to be edited - are not easy. Just note that in the previous reproduction log, those lines weren't printed for me outside of Zellij in a pane with identical size. I'll need a log that produces the intended different behavior in and out of Zellij in a pane of the same stty size in order to find the issue here.

imsnif avatar Jul 22 '24 14:07 imsnif

I haven't had the chance to retest/investigate this further (I worked around the issue by piping to a pager). Closing this issue for now.

Hylian avatar May 14 '25 17:05 Hylian