Skip to content

Conversation

sechmann
Copy link
Contributor

@sechmann sechmann commented Jun 24, 2025

This fixes links in terminals that support links and use tmux.

The problem is that tmux sets "TERM_PROGRAM", and with this introduction of the early return here it no longer works when running tmux in a supported terminal (i.e. TERM=xterm-ghostty)

@savioxavier
Copy link
Owner

tmux has some very concerning behavior, please see issue #14, as well as my comments #14 (comment) and #14 (comment)

@sechmann
Copy link
Contributor Author

sechmann commented Jun 24, 2025

This "fix" is not specific to tmux though, it will just continue checking for other supported terminals even when TERM_PROGRAM is set. This was the behaviour previous to the iterm support commit.

Let's say kitty starts setting TERM_PROGRAM=kitty. This would break links in kitty until you add that to the switch, even though there is code below the switch that would detect that it's kitty, but this is unreachable because of the return in the switch statement.

Edit: if the point of the return is to block tmux, it would be clearer with a:

case "tmux":
	return false

@savioxavier
Copy link
Owner

Good catch! I didn't think of it like that.

Edit: if the point of the return is to block tmux, it would be clearer with a:

case "tmux":
  return false

Do you think it would be a good idea to include this? I haven't used tmux personally so I don't really know if tmux sets TERM_PROGRAM=tmux all the time. Sure, I want to allow users to view hyperlinks whenever their terminal supports it, but I still have to ensure that they don't see a bunch of random ANSI codes if their terminal is unsupported.

If you have no other comments to add, I'll merge your changes.

@sechmann
Copy link
Contributor Author

sechmann commented Jun 26, 2025

I don't think it would be a good idea to block tmux, as the function already returns false for all unknown terminals.

Tmux supports hyperlinks just fine (as long as underlying terminal supports it), but to make the links clickable you have to enable that in the configuration. When it is not enabled, the links will render like links, but can't be clicked. Tools (like this) that work with links in the buffer however will interpret them as links and be able to open them regardless of configuration.

I don't see any way this change would lead to more terminals showing mangled output, as unknown terminals would still reach the end of the function and get false returned.

If you have no other comments to add, I'll merge your changes.

Nice, thanks!

@savioxavier savioxavier merged commit f49d414 into savioxavier:master Jun 28, 2025
1 check passed
@savioxavier
Copy link
Owner

Thank you for your contribution to termlink. See https://github.com/savioxavier/termlink/releases/tag/v1.4.3 for changes

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.

2 participants