Repository: zellij-org/zellij (language: rust)

Issue:
sixels printed inside terminal emulator does not get cleared
# 1. Graphical issue inside a terminal pane (eg. something does not look as it should)

1. Delete the contents of `/tmp/zellij-1000/zellij-log`, ie with `cd /tmp/zellij-1000/` and `rm -fr zellij-log/` (`/tmp/` is `$TMPDIR/` on OSX)
2. Run `zellij --debug`
3. Run `stty size`, copy the result and attach it in the bug report
4. Recreate your issue.
5. Quit Zellij immediately with ctrl-q (your bug should ideally still be visible on screen)

Please attach the files that were created in `/tmp/zellij-1000/zellij-log/` to the extent you are comfortable with.

**Basic information**

`zellij --version`: zellij 0.39.2

`stty size`: 52 208

`uname -av` or `ver`(Windows): Linux sam-computer 6.7.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 23 Feb 2024 16:31:48 +0000 x86_64 GNU/Linux

## Further information
Reproduction steps, noticeable behavior, related issues, etc

after running img2sixel /path/to/png.png and then running the clear command the image does not get cleared from the screen
this is in the alacritty graphics branch that is working flawlessly outside of zellij

[zellij.log](https://github.com/zellij-org/zellij/files/14453840/zellij.log)



Discussion / hints:
just tested with xterm too and same issue with sixels not getting cleared when running clear command
As @Zettexe pointed out in #3372 , this is probably a consequence of sixel images being rendered with twice the height they should. Example:

![image](https://github.com/zellij-org/zellij/assets/6536835/38a6037a-0260-4702-9fa8-7b5753c0de08)

[link to the test image](https://codeberg.org/coffee/sixel-experiments/raw/commit/4c05e577fbecb75d9f6bccbe18a1e7e8dc10d098/text-test.sixel)
> As @Zettexe pointed out in #3372 , this is probably a consequence of sixel images being rendered with twice the height they should. Example:
> 
> ![image](https://private-user-images.githubusercontent.com/6536835/346637220-38a6037a-0260-4702-9fa8-7b5753c0de08.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMjE2NjIsIm5iZiI6MTcyMTMyMTM2MiwicGF0aCI6Ii82NTM2ODM1LzM0NjYzNzIyMC0zOGE2MDM3YS0wMjYwLTQ3MDItOWZhOC03YjU3NTNjMGRlMDgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MThUMTY0OTIyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjVjNDNmM2Y3ZDUwOTY4YmJhMjlkODczZDAyZjEwMWY0ODc3ZGEwY2Y5NjMwODUxMDVjMWU4NTE0MzIxNzQxNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.sEfYLX-mFaMuPUB2Esh6Inst5orcuOzaSRJVU999tNk)
> 
> [link to the test image](https://codeberg.org/coffee/sixel-experiments/raw/commit/4c05e577fbecb75d9f6bccbe18a1e7e8dc10d098/text-test.sixel)

Nice test case. I'll look into this issue next as it's breaking my sixel based workflow.
Weirdly enough, I recently switched to a [branch of Alacritty with sixel support](https://github.com/alacritty/alacritty/pull/4763) and there zellij's sixel are correct... 

![image](https://github.com/user-attachments/assets/3aa357f8-9ae5-459d-97b1-c38c5cdbd7a4)

next week I got some time, I will investigate
This may be the key - foot supports aspect ratios and defaults to 2:1. I'll look into this part of the zellij code this coming week.

On Sat, Jul 20, 2024, at 21:12, Manuel de Prada Corral wrote:
> 
> 
> Weirdly enough, I recently switched to a branch of Alacritty with sixel support <https://github.com/alacritty/alacritty/pull/4763> and there zellij's sixel are correct...
> 
> image.png (view on web) <https://github.com/user-attachments/assets/3aa357f8-9ae5-459d-97b1-c38c5cdbd7a4>
> 
> next week I got some time, I will investigate
> 
> 
> —
> Reply to this email directly, view it on GitHub <https://github.com/zellij-org/zellij/issues/3173#issuecomment-2241265469>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAACN4JNHXVQUH6IXLVJ7DZNKZDVAVCNFSM6AAAAABEAWJTWKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBRGI3DKNBWHE>.
> You are receiving this because you commented.Message ID: ***@***.***>
> 
Yeah that's it, I was able to use wezterm record to show that zellij is not passing through the raster attributes needed to fix the default 2:1 ratio (spec default) that foot uses and other terminal emulators fail to correctly default to. Comment from Aram on the line in question: ```// we ignore pan/pad because (reportedly) no-one uses them```. Alas some emulators are trying to get to spec on this. I'll look into writing a patch to pass this through from the tokenizer.
Okay verified the theory by hacking sixel-image to always spew a hardcoded override to 1:1 ratio. Foot now renders your test case correctly. Next up will be to understand enough of the spec to add pan/pad roundtripping and understand how that fits into Aram's concerns.

![image](https://github.com/user-attachments/assets/4c431e49-9220-4b77-a6f3-86f2848fd548)


Fix patch:
diff --git a/zellij-server/src/panes/grid.rs b/zellij-server/src/panes/grid.rs
index 34f689864f..09fb00d1a2 100644
--- a/zellij-server/src/panes/grid.rs
+++ b/zellij-server/src/panes/grid.rs
@@ -2632,8 +2632,14 @@ impl Perform for Grid {
                 } else if clear_type == 2 {
                     self.set_scroll_region_to_viewport_size();
                     self.fill_viewport(char_to_replace);
+                    if let Some(images_to_reap) = self.sixel_grid.clear() {
+                        self.sixel_grid.reap_images(images_to_reap);
+                    }
                 } else if clear_type == 3 {
                     self.clear_lines_above();
+                    if let Some(images_to_reap) = self.sixel_grid.clear() {
+                        self.sixel_grid.reap_images(images_to_reap);
+                    }
                 }
             };
         } else if c == 'H' || c == 'f' {


Test patch: