kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.16k stars 972 forks source link

Images/graphics are not cleared up inside tmux #2457

Closed wookayin closed 4 years ago

wookayin commented 4 years ago

I know tmux is a big headache when it comes to implement features involving escaping sequence. Somehow I managed to prototype the image preview feature in tmux (#413) work on kitty, via tmux passthrough sequence. Yay!

image

However there is a problem with images: it does not get cleared up after <Ctrl-L> (clear).

The clear screen escape code (usually [2J) should also clear all images. This is so that the clear command works.

image

So it either stacks up: image

or after reattach/deattach/split panes/or whenever re-rendering happens:

image

a black image hides everything.

It seems that there is something weird happening in dealing with clear sequence. Any ideas for workaround?

FYI, iTerm2 simply clears up all rendered images whenever the graphics gets out of the screen (e.g., scrolled up, detach, redraw, clear, etc.). Another workaround is to have a feature to manually clean up the rendered graphics (via mouse pop-up menu or some command lines).

kovidgoyal commented 4 years ago

clear clears all images. If it does not work with tmux that will be because tmux is screwing things up, as usual. If you want to manually clear images, use kitty + kitten icat --clear

wookayin commented 4 years ago

I know. As I said, tmux is a big trouble. But why closing this issue? Could you please reopen it or discuss some workaround or about adding more batteries?

kitty +kitten icat --clear does not work inside tmux because the lack of TIOCGWINSZ support (#413). I think we can use other ways to get the screen size, e.g. stty size though. We should have at least some manual way --- either with mouse clicks or some command lines --- to clear up all graphics despite the tmux messup.

Anyway, what kitty +kitten icat --clear does is to emit the following control sequence:

\x1b_Ga=d,d=A\x1b\\

It has no effect inside tmux. Still the "ghost" graphics are not cleared up.

kovidgoyal commented 4 years ago

There's nothing I can do about issues tmux creates. If you wish to discuss workarounds for tmux, feel free to do so, but this is not a kitty issue. Using clear and icat --clear both work without tmux. That's more than enough ways to clear images, as provided by kitty.

wookayin commented 4 years ago

tmux says that it is not a problem of theirs and so does kitty. But thanks for letting me know the clear sequence used in kitty. Although this is a tmux create, I think kitty is fully responsible of cleaning up all graphics garbages created by whatever reason.

So the following sequence -- must be wrapped by tmux passthrough sequence protocol -- works for clearing all graphics:

>>> sys.stdout.buffer.write(b'\033Ptmux;\033' + b'\033_Ga=d,d=A\033\033\\' + b'\033\\')

but only if the graphics are in display. In other words, in the presence of the "ghost" black graphics (where the actual images are gone) for some reason (e.g. deattach and reattach, or scroll a lot), the control sequence would not clear up them. I think this is just a small bug, but do you think it would be fixable?

kovidgoyal commented 4 years ago

On Sat, Mar 21, 2020 at 09:23:58PM -0700, Jongwook Choi wrote:

tmux says that it is not a problem of theirs and so does kitty. But thanks for letting me know the clear sequence used in kitty. Although this is a tmux create, I think kitty is fully responsible of cleaning up all graphics garbages created by whatever reason.

tmux is interfering with the escape codes sent by the applications running in the terminal. If they do that, then it is their problem to fix the resulting breakage. Terminal multiplexers are an extremely bad idea that both breaks things and wastes energy. I have said so plenty of times before and will continue to say so.

So the following sequence -- must be wrapped by tmux passthrough sequence protocol -- works for clearing all graphics:

>>> sys.stdout.buffer.write(b'\033Ptmux;\033' + b'\033_Ga=d,d=A\033\033\\' + b'\033\\')

All escape sequences are documented, https://sw.kovidgoyal.net/kitty/graphics-protocol.html

but only if the graphics are in display. In other words, in the presence of the "ghost" black graphics (where the actual images are gone) for some reason (e.g. deattach and reattach, or scroll a lot), the control sequence would not clear up them. I think this is just a small bug, but do you think it would be fixable?

There are no ghost graphics, if there are, then it is a bug and should be fixed. One such bug was recently fixed in master, look for the commits from the last couple of days.

wookayin commented 4 years ago

Thanks Kovid. With due respect, I would say I don't think terminal multiplexer is a bad idea. But I understand why you believe so. This is beyond this issue's scope, so let's stop the argument here.

I tried the latest master as of 3/21 and yes, the bug is no more present (all graphics are cleared). Seems fixed in #2449. For the v0.16.0 release I can always confirm the bug exists, so we can say everything is okay from v0.17. Now I think I have all toolsets I needed. Thank you for your help again!

AnonymouX47 commented 2 years ago

@wookayin Display an image, then try scrolling in tmux and see what happens... or display an image with a height greater than the tmux pane's height.

My point is... it's mostly futile trying to make the graphics protocol work in tmux if its maintainers decide not to do something about it (which would actually be quite a hell of work for them).