kovidgoyal / kitty

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

Making `kitty icat` work in tmux popup #7165

Closed junegunn closed 7 months ago

junegunn commented 7 months ago

Is your feature request related to a problem? Please describe.

Currently, kitty icat does not work inside a tmux popup.

Error: Terminal does not support reporting screen sizes in pixels, use a terminal such as kitty, WezTerm, Konsole, etc. that does.

This is probably due to a limitation of the tmux popup implementation. It doesn't report the correct pixel sizes.

tmux popup 'kitty icat --print-window-size'
  # Gives 0x0

Describe the solution you'd like

However, tmux does know the pixel size of a cell even from inside the popup.

tmux popup 'tmux display -p "#{client_cell_width}x#{client_cell_height}"'
  # Gives something like 17x37

(See https://github.com/tmux/tmux/commit/067604bf8cb23c1a208d26d94dbae7c2ab46dabf)

So maybe we could pass the information to kitty icat (e.g. something like kitty icat --cell-size 17x37 ...) and make it work even with the current limitation of tmux popup.

Describe alternatives you've considered Ideally, we could report the problem to the tmux team and wait for the fix. But they don't seem to be as responsive and cooperative as you are, so I'm contacting you first to see how you feel about the workaround.

kovidgoyal commented 7 months ago

This is clearly a bug in tmux, with a trivial fix there. I suggest reporting it there first, and if they refuse to fix it, then I will add yet another workaround for tmux brokenness.

junegunn commented 7 months ago

I understand. And, thank you for the patch!

junegunn commented 7 months ago

Update:

I've installed Kitty nightly and tested kitty icat inside a tmux popup. But unfortunately it doesn't work as expected.

# Works
kitty icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place=202x13@0x0 --use-window-size=202,13,3434,481 $PWD/fzf.png

# Doesn't display the image
tmux popup -w 202 -h 13 "kitty icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place=202x13@0x0 --use-window-size=202,13,3434,481 $PWD/fzf.png"

I believe this is an issue of the tmux popup not of kitty. Thanks for the help.


One more thing. This is a user error, but icat fails with divide by zero error when the specified pixel width is smaller than the column count. e.g. --use-window-size=202,13,201,481

kitty icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place=202x13@0x0 --use-window-size=202,13,201,481 $PWD/fzf.png
panic: runtime error: integer divide by zero

goroutine 1 [running]:
kitty/kittens/icat.calculate_in_cell_x_offset(...)
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/kittens/icat/transmit.go:198
kitty/kittens/icat.place_cursor(0x103287580?)
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/kittens/icat/transmit.go:215 +0x284
kitty/kittens/icat.transmit_image(0x140000b80d0)
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/kittens/icat/transmit.go:338 +0x224
kitty/kittens/icat.main(0x140001ca200?, 0x1400036a0f0?, {0x140001bab00, 0x1, 0x8})
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/kittens/icat/main.go:289 +0xd8c
kitty/kittens/icat.create_cmd.func1(0x140001ca200, {0x140001bab00, 0x1, 0x8})
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/kittens/icat/cli_generated.go:15 +0x90
kitty/tools/cli.(*Command).ExecArgs(0x1400013c000?, {0x140000dc000?, 0x0?, 0x140001cba00?})
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/tools/cli/command.go:546 +0x244
kitty/tools/cli.(*Command).Exec(0x1400013c000?, {0x0?, 0x60?, 0x0?})
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/tools/cli/command.go:564 +0x3c
main.main()
        /private/var/folders/wj/cqy1nsyn4wn94d96btkldt0r0000gn/C/t/plugins-daba4sw5/src/tools/cmd/main.go:34 +0x13c
kovidgoyal commented 7 months ago

https://github.com/kovidgoyal/kitty/commit/a3d8be5e2f82fa36e128171a914cd25054b40c9f