8000 use tmux passthrough for kitty graphics protocol by l4zygreed · Pull Request #3086 · ranger/ranger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

use tmux passthrough for kitty graphics protocol #3086

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

l4zygreed
Copy link
@l4zygreed l4zygreed commented Apr 27, 2025

Updated Ethan PR for current master

ISSUE TYPE

  • Improvement/feature implementation

RUNTIME ENVIRONMENT

  • Operating system and version: Macos sequoia 15.4
  • Terminal emulator and version: Ghostty 1.1.3
  • Python version: 3.13.3
  • Ranger version/commit: ranger-master v1.9.3-794-gcf51b12f
  • Locale: en_US.UTF-8

CHECKLIST

  • The CONTRIBUTING document has been read [REQUIRED]
  • All changes follow the code style [REQUIRED]
  • All new and existing tests pass [REQUIRED]
  • Changes require config files to be updated
    • Config files have been updated

DESCRIPTION

Updated PR #2856 to be compatible with current master branch.

MOTIVATION AND CONTEXT

Want to finally see images inside tmux on my mac and outside of iterm/kitty terminal 😆
Found old Ethan PR and decided to resolve conflicts and update it for current master

TESTING

  • make test executed successfully
  • kitty without tmux
  • kitty with tmux and allow-passthrough not set
  • kitty with tmux and allow-passthrough set
  • ghostty without tmux
  • ghostty with tmux and allow-passthrough not set
  • ghostty with tmux and allow-passthrough set

IMAGES / VIDEOS

cleanshot.mp4

Copy link
@Ethsan Ethsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the keeping the pr alive and the update, it's cleaner now!

Should we separate the commit in two ? Something like :

  • support for virtual placement using unicode placeholder
  • support for tmux allow-passthrough mode

Moreover some minor changes below.

l4zygreed and others added 2 commits May 18, 2025 07:50
Updated Ethan PR for current master

Co-authored-by: Ethan <milonthan@gmail.com>
Updated Ethan PR for current master

Co-authored-by: Ethan <milonthan@gmail.com>
@l4zygreed l4zygreed force-pushed the feat/kitty_in_tmux branch from 3608676 to 3ac971f Compare May 18, 2025 04:55
@Ethsan
Copy link
Ethsan commented May 18, 2025

Resolve #2414, Resolve #2846, Resolve #3072

@toonn
Copy link
Member
toonn commented May 19, 2025

Do the resolve comments work in comments or should they be part of commit messages?
(Since this seems to work for both of you I think it's had enough testing. Feel free to pester me once a week until I review and merge.)

@Ethsan Ethsan mentioned this pull request May 19, 2025
5 tasks
@Ethsan
Copy link
Ethsan commented May 19, 2025

Hi,

Do the resolve comments work in comments or should they be part of commit messages?

From what I read, the resolve don't work in comment, so they should be part of the commit message. I have commented them so we don't have to search them later.

(Since this seems to work for both of you I think it's had enough testing. Feel free to pester me once a week until I review and merge.)

Ok, the PR seems good for me.

@Ethsan Ethsan force-pushed the feat/kitty_in_tmux branch from 5e06dd4 to 66c1488 Compare May 22, 2025 22:53
@Ethsan Ethsan force-pushed the feat/kitty_in_tmux branch from 153c40b to 62c8d89 Compare May 22, 2025 23:00
@Ethsan
Copy link
Ethsan commented May 22, 2025

Hi,
@toonn do you prefer something like that ? or should we revert ?


try:
with open(
self.fm.relpath("rowcolumn-diacritics.txt"),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
10000
self.fm.relpath("rowcolumn-diacritics.txt"),
self.fm.relpath(data”, “rowcolumn-diacritics.txt"),

@Ethsan you placed file in data folder, so the path is incorrect and throws error.
also why file named txt while it’s treated like csv? 🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

@Ethsan you placed file in data folder, so the path is incorrect and throws error.

Yeah sorry about that, I move it will trying ot fix linting issues and forgot to update path.

also why file named txt while it’s treated like csv? 🤔

I have simply reused the name given upstream rowcolumn-diacritics.txt

Copy link
Member
@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW in the future I'd prefer if people tried to PR to the PR branch of the original PR author, possibly linking to the downstream PR in our PR comments. It's inconvenient to keep track of things if people keep opening new PRs that are really the same thing. Rebasing on master is usually quite trivial so you can rest assured that that is not what holds back a PR from getting merged.

In this case Ethsan seems perfectly happy with the situation but it can come across as trying to take credit for someone else's work. All of this is easily avoided by opening the PR against their PR branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was kinda hoping to read this from wherever Kitty or Ghostty install it on the system but I guess this makes it compatible with other terminals too.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would have been cleaner.

For example, icat from the kitty repo use an array with the unicode character, like in the original idea.

newline="",
encoding="utf-8",
) as file:
reader = csv.reader(file, delimiter=";")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is csv.reader more performant than rolling our own? It's just some hex digits from the starts of lines, right? I'd expect parsing the entire lines to take a little bit longer.

except CalledProcessError:
tmux_allow_passthrough = b'off'
if tmux_allow_passthrough == b'off':
raise ImageDisplayError("allow-passthrough no set in Tmux!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ImageDisplayError("allow-passthrough no set in Tmux!")
raise ImageDisplayError("allow-passthrough is not set in Tmux!")

# convert hex code to int and then to unicode char
self.diacritics = [chr(int(hex, 16)) for hex in hex_list]
except Exception as err:
raise ImageDisplayError("Error while loading diacritics" + str(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ImageDisplayError("Error while loading diacritics" + str(err))
raise ImageDisplayError("Error while loading diacritics: " + str(err))

Comment on lines +701 to +702
answer_start = protocol_start
answer_end = protocol_end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is honestly a bit confusing. Why are we initializing two sets of these? Do we need answer_start after changing protocol_start while also not being able to use it instead of protocol_start before changing it?

Comment on lines +732 to +733
# check if we inside tmux
# if true then we use the tmux escape sequence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# check if we inside tmux
# if true then we use the tmux escape sequence
# Use Tmux escape sequence if appropriate.

Comment on lines +810 to +812
# check if tmux allows passthrough
# use tmux escape sequence if it's enabled
# throw error if it's disabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# check if tmux allows passthrough
# use tmux escape sequence if it's enabled
# throw error if it's disabled
# Check whether allow-passthrough is enabled

# catch kitty answer before the escape codes corrupt the console
resp = b''
while resp[-2:] != self.protocol_end:
while resp[-2:] != self.answer_end:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use endswith here too?

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

Successfully merging this pull request may close these issues.

3 participants
0