zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
19.98k stars 626 forks source link

ANSI control codes corrupt view #3489

Open Hylian opened 3 weeks ago

Hylian commented 3 weeks ago

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

zellij_test.log

zellij.log

zellij-14.log

imsnif commented 3 weeks ago

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 commented 3 weeks ago

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).

Hylian commented 3 weeks ago

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 commented 3 weeks ago

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:

Observed behavior:

stty size: 63 280

imsnif commented 2 weeks ago

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!

Hylian commented 2 weeks ago

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

imsnif commented 2 weeks ago

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.