Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmux show picture is blur #95

Closed
newyorkthink opened this issue Nov 25, 2022 · 18 comments
Closed

tmux show picture is blur #95

newyorkthink opened this issue Nov 25, 2022 · 18 comments

Comments

@newyorkthink
Copy link

newyorkthink commented Nov 25, 2022

No description provided.

@hzeller
Copy link
Owner

hzeller commented Nov 25, 2022

tmux will limit the number of unicode characters and colors it can show. This is nothing timg or other terminal image displaying tools will be able to influence. Maybe it is something that you can configure in tmux already or have to implement there.

So this is not an issue with timg but something you have to figure out with tmux.

@hzeller
Copy link
Owner

hzeller commented Nov 25, 2022

I don't think that tmux allows the picture modes of kitty or wezterm. This is why images are shown in the character based pixelation.

Also 256 colors is limiting the color range, you'd like a 24 bit color mode if available.

@gsbabil
Copy link

gsbabil commented Jun 29, 2023

There's a tmux plugin/kitten called icat which if used inside kitty > tmux (tmux running inside kitty) can draw images in full resolution using the kitty protocol.

But under the same kitty > tmux setup, the same image if displayed with timg, will appear blurred with --pixelation=quarter (default behavior), or as text if --pixelation=kitty is used (example screenshot below).

📍 Since icat works under the kitty > tmux setup, timg --pixelation=kitty should also work under the same kitty > tmux setup as well. Thanks!

image

@hzeller
Copy link
Owner

hzeller commented Jun 29, 2023

Interesting, I'll have to look what the difference is of what icat outputs on tmux vs. timg.

@gsbabil
Copy link

gsbabil commented Jun 29, 2023

@hzeller Thanks. For the sake of completeness...

@hzeller
Copy link
Owner

hzeller commented Jul 1, 2023

I looked what kitty is doing there. It has to do an extremely ugly hack to work around tmux' refusal to work with image protocols.
I'll have to see if I can integrate that in timg without breaking anyone else who is implementing that protocol.

hzeller added a commit that referenced this issue Jul 15, 2023
In general, this is a way to work around tmux that can't deal with
graphics protocols directly.
https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders

The needed workaround is not pretty, but that's all we got :/

This is a preparation to output properly tmux-escaped Unicode
placeholders (not wired up yet).

The default behavior without tmux of Kitty stays as-is (no
Unicode Placeholders) to be compatible with terminals that just
implement the image sub-set of the Kitty protocol.

Issues: #95
hzeller added a commit that referenced this issue Jul 15, 2023
When we see tmux, we need to do things differently, so let's
bubble that up from when we query the terminal anyway.

Issues: #95
hzeller added a commit that referenced this issue Jul 15, 2023
When we see tmux, we need to do things differently, so let's
bubble that up from when we query the terminal anyway.

Issues: #95
@hzeller
Copy link
Owner

hzeller commented Jul 15, 2023

Can you try this AppImage zip ?

It should now work within tmux running inside the Kitty terminal (other terminals that support the Kitty protocol will likely not work as the Unicode Placeholder stuff is fairly new and probably only implemented properly there).

You have to manually provide the -pk option in timg for it to emit the Kitty protocol (because timg can't probe the terminal (Or, manually set the TERM environment variable to xterm-kitty).

# inside tmux
$ timg -pk some-image.jpg

@gsbabil
Copy link

gsbabil commented Jul 16, 2023

@hzeller Thanks for the quick turnaround! Please see my test results below.

Kitty 0.28.1 > Tmux 3.3a

  • ✅ Everything seems to work in this configuration as expected. Thanks!
image

Kitty 0.28.1 > Tmux 3.3a > SSH (Ubuntu/Linux)

  • ⚠️ This configuration also works, but with the following error:
no server running on /tmp/tmux-1001/default
Could not set tmux passthrough for graphics
image
  • 📌 I think before doing system("tmux set -p allow-passthrough on"), we need to check if we are running inside tmux, e.g. at the SSH Linux host, we were not running tmux in this configuration.
    • timg/src/timg.cc

      Lines 789 to 791 in 5c5560d

      if (system("tmux set -p allow-passthrough on") != 0) {
      fprintf(stderr, "Could not set tmux passthrough for graphics\n");
      }

Kitty 0.28.1 > Tmux 3.3a > SSH (Ubuntu/Linux) > Tmux 3.2a

  • ⛔️ This configuration does not work (displays no/blank image) and prints the following error/warning:
invalid option: allow-passthrough
Could not set tmux passthrough for graphics
image
  • 📌 I think this is because tmux didn't support the allow-passthrough option in 3.2a. So, before doing system("tmux set -p allow-passthrough on"), we need to somehow check the underlying tmux version. Thanks!

@gsbabil
Copy link

gsbabil commented Jul 16, 2023

In case anyone else is struggling to reproduce the same behavior from the latest timg patch under Kitty v0.28.1 and v.29 (latest), this might be the reason. Thanks.

@hzeller
Copy link
Owner

hzeller commented Jul 16, 2023

Second case: ok, let me see if there is a simple way to detect the case where we're actually remote.

The last case, tmux before 3.3, probably just means that if passthrough didn't exist then, it would not possible to show images in tmux anyway, so showing an error message there is probably good, but I agree if we could take the version into account, we could provide a more tailored error message.

@hzeller
Copy link
Owner

hzeller commented Jul 16, 2023

Alright, the cases 2 and 3 should be a bit more useful now

  • Case 2, possibly case 3: Remote ssh situation with tmux invoked on the remote site: Don't print error message in that case
  • Case 3: if we get an error (exit code 1) that indicates that tmux set could be executed, but that option doesn't exist, say so and hint that at least version 3.3 is needed.

There is an updated AppImage to test.

@hzeller
Copy link
Owner

hzeller commented Jul 17, 2023

Now in the latest release v1.5.1

@hzeller
Copy link
Owner

hzeller commented Jul 17, 2023

yes, tmux is refusing to work with image formats, so the Kitty workaround is the only way.

@hzeller hzeller closed this as completed Jul 17, 2023
@gsbabil
Copy link

gsbabil commented Jul 17, 2023

@hzeller Thanks again.

  • ✅ Both cases 2 and 3 are working as desired. Thanks!
  • 📌 A minor improvement could be that when we can't enable the passthrough mode, we do not allocate the space to draw the image (screenshot below). Thanks a lot!
image

@hzeller
Copy link
Owner

hzeller commented Jul 17, 2023

FYI @kovidgoyal : implemented use of your unicode placeholders protocol to have timg work within tmux within kitty.

@kovidgoyal
Copy link

Cool, glad to hear it.

@rpdelaney
Copy link

Anyone have working usage examples for scope.sh in tmux? I'm having... problems...

@m040601
Copy link

m040601 commented Sep 3, 2023

Just to give my 2 cents feedback.

This is working perfectly on my Archlinux system. That is, when I'm running tmux inside kitty and,

timg --pixelation=kitty someimage.jpg

I see a perfect not blurred image.

It "seems" to take a few almost unnoticeable micro/nano milliseconds more time than showing it without tmux in the middle. This is a 14 year old PC' ahha.

timg --version

timg 1.5.2+  <https://timg.sh/>
Copyright (c) 2016..2023 Henner Zeller. This program is free software; license GPL 2.0.

Image decoding GraphicsMagick 1.3.41 (2023-08-12)
Openslide 3.4.1
Turbo JPEG
QOI image loading
swscale 7.1.100
Video decoding libav 60.3.100; avdevice 60.1.100
Half, quarter, iterm2, and kitty graphics output: timg builtin.
Libsixel version 1.10.3

Installed from here, https://aur.archlinux.org/packages/timg

$ kitty --version

kitty 0.29.2 created by Kovid Goyal

$ tmux -V

tmux 3.3a

I always have this line in my ~/.tmux.conf

set -g default-terminal "tmux-256color"

and that's what is reported by echo $TERM.

From the 3 terminal image viewers that I use

timg is the only one that "manages" to do it. That is, to overcome tmux "obstacles" and display a perfect image , when running inside tmux inside kitty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants