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

Add support for hyperlink OSC #468

Closed
wants to merge 1 commit into from
Closed

Conversation

emersion
Copy link
Contributor

Closes: #300

Not sure what's the best way to add this to our terminfo.

Tested with foot using this small demo patch:

diff --git a/_demos/hello_world.go b/_demos/hello_world.go
index 196f0a52928c..0e51e443365a 100644
--- a/_demos/hello_world.go
+++ b/_demos/hello_world.go
@@ -43,7 +43,7 @@ func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) {
 func displayHelloWorld(s tcell.Screen) {
 	w, h := s.Size()
 	s.Clear()
-	style := tcell.StyleDefault.Foreground(tcell.ColorCadetBlue.TrueColor()).Background(tcell.ColorWhite)
+	style := tcell.StyleDefault.Foreground(tcell.ColorCadetBlue.TrueColor()).Background(tcell.ColorWhite).Hyperlink("https://example.org")
 	emitStr(s, w/2-7, h/2, style, "Hello, World!")
 	emitStr(s, w/2-9, h/2+1, tcell.StyleDefault, "Press ESC to exit.")
 	s.Show()

t.TPuts(ti.Hyperlink + style.hyperlink + ti.StringTerminator)
} else if t.curstyle.hyperlink != "" && ti.Hyperlink != "" {
t.TPuts(ti.Hyperlink + ti.StringTerminator)
}
Copy link
Owner

Choose a reason for hiding this comment

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

I am concerned that the style code checks may cause gross inefficiencies -- we have to emit this value when changing the style, and now this string has to be part of that.

This also increases the size of the style -- which might be ok, but I've got some efficiency concerns.

I need to look at this in more depth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am concerned that the style code checks may cause gross inefficiencies -- we have to emit this value when changing the style, and now this string has to be part of that.

What do you mean? The new OSC is only emitted when the hyperlink changes -- which should happen exactly as many times as there are hyperlinks on screen. I don't think there's a better way to reduce the number of OSC sequences.

This also increases the size of the style -- which might be ok, but I've got some efficiency concerns.

I don't think this is a big issue -- are there any benchmarks? Do you have any suggestions to improve this?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure the statement about when it is emitted is strictly true.

For example, what if part of your link is covered by a different style.

I also want to make sure that the check for style equality still works -- there is definitely code that tries to minimize changing attributes, and I'm not sure what the interaction will be. Mostly I just need to dig into this to be sure this works as intended.

Copy link
Owner

Choose a reason for hiding this comment

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

So, what I really want to do is refactor this slightly to use string based capabilities in terminfo. I think that will be a fair bit cleaner. Other than that it looks pretty good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, thanks for the feedback, I'll look into this.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm still not loving the separate begin and end hyperlink bits... but it might be the best approach.

Copy link
Owner

Choose a reason for hiding this comment

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

There's also a problem with %s I think (possible conflation with other bits in the terminfo standard.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still not loving the separate begin and end hyperlink bits... but it might be the best approach.

I don't think there's a way around it. There can be arbitrary escape codes between the start of an hyperlink and its end, including e.g. color changes and other style changes. Having a single escape code for hyperlinks won't cut it.

There's also a problem with %s I think (possible conflation with other bits in the terminfo standard.)

Any suggestions to use something else? Would %v be better?

Copy link
Owner

Choose a reason for hiding this comment

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

In terminfo, %s is the right thing to use here, but technically it should be used with a pop operation. I need to review the code to see the best way to achieve what we want.

terminfo/terminfo.go Outdated Show resolved Hide resolved
@emersion
Copy link
Contributor Author

Is this new version better?

@emersion
Copy link
Contributor Author

Ping @gdamore

@gdamore
Copy link
Owner

gdamore commented Nov 23, 2021

Sorry, I'll have a look at this sometime this week. Been pretty busy with other stuff lately.

@microo8
Copy link

microo8 commented Apr 15, 2022

How is it going? I would like to use it in my app.

@emersion
Copy link
Contributor Author

FWIW, we've switched to using a fork over at https://github.com/delthas/tcell/tree/dev.

@microo8
Copy link

microo8 commented Apr 15, 2022

Oh thanks @emersion, I'll have a look at it.

tulir added a commit to tulir/tcell that referenced this pull request Apr 15, 2022
@gdamore
Copy link
Owner

gdamore commented Apr 16, 2022

I am working on changes inspired by this branch, but there are a few differences.

  1. I've made the underlying terminfo work properly with %s as per terminfo definitions.
  2. Instead of Hyperlink the attribute is called Url.

I should have this out later today.

@gdamore
Copy link
Owner

gdamore commented Apr 16, 2022

Please have a look at #527 which largely builds upon your work, although there are some significant changes. The API is slightly different (see style.Url() instead of style.Hyperlink())

@gdamore
Copy link
Owner

gdamore commented Apr 16, 2022

I'd like to go ahead and merge that new work, but would like to give folks a chance to comment first.

@gdamore
Copy link
Owner

gdamore commented Apr 17, 2022

I'm closing this for now. Please see the new Url() API which is somewhat derived from this work, but I've made my own changes that I think is truer to the spirit.

I'll be adding support for more OSC capabilities soon as well. :-)

@gdamore gdamore closed this Apr 17, 2022
@microo8
Copy link

microo8 commented Apr 18, 2022

It works great and it's pretty simple and elegant :) thanks

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.

Implement terminal hyperlinks
3 participants