aurora icon indicating copy to clipboard operation
aurora copied to clipboard

Adds support for Hyperlinks

Open jphastings opened this issue 4 years ago • 6 comments

Adds support for Hyperlinks in many modern terminal emulators, as described in this gist.

package main

import (
  "fmt"
  "github.com/logrusorgru/aurora"
)

func main() {
  fmt.Println("Now with ", aurora.Link("links", "https://github.com/logrusorgru/aurora"))
}

jphastings avatar Feb 05 '21 20:02 jphastings

Coverage Status

Coverage remained the same at 100.0% when pulling c91a2c1016abae26b951524e50afc1189ef6cb2e on jphastings:feature/hyperlinks into 806901bec141cfa65f25b4472d5fb1b461609771 on logrusorgru:master.

coveralls avatar Feb 05 '21 20:02 coveralls

These tests are a little awkward, as the hyperlink escape codes are of a very different structure to the colourising ones, but this gets coverage back to 100% and allows the PR to go green!

Do let me know if you think there's a better approach!

jphastings avatar Feb 09 '21 22:02 jphastings

Hello, @jphastings! There are some notes...

  1. It should be implemented like this
func (v value) Link(url string) Value {
	return valueLink{value: v, url: url}
}

// a value with a link

type valueLink struct {
	value
	url string
}

func (v valueLink) String() string {
	// TODO: link
	return v.value.String() // TODO: link
}

func (v valueLink) Reset() Value {
	v.color, v.tailColor, v.url = 0, 0, ""
	return v
}

func (v valueLink) Format(s fmt.State, verb rune) {
     // TODO: with the link
}

func (v valueLink) Link(url string) Value {
	v.url = url // change
	return v
}

This way the value will not be encomplicated with additional 'url' that is not used in most cases. And the valueLink just overwrites required methods. Inheriting all other methods from the value type.

  1. The String methods also should return necessary escape sequences.
  2. In reality it looks like something like

2021-02-06_03-39

(example for XFCE4 terminal). No link target shown, no pointer cursor. Just a text. We need add this important note into README. Because users, I think, expect something other.

logrusorgru avatar Feb 27 '21 09:02 logrusorgru

misfeature

logrusorgru avatar Sep 02 '22 17:09 logrusorgru

Unfortunately, author of the feature https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda removes comments from the discussion. Thus, no explanation has survived.

logrusorgru avatar Sep 02 '22 17:09 logrusorgru

Finally, I've got the explanation, I need some work around this PR and bump v4.... Soon.

logrusorgru avatar Oct 05 '22 06:10 logrusorgru

You'd like some changes from me?

jphastings avatar Oct 05 '22 21:10 jphastings

You'd like some changes from me?

No, thank, you, I will make them myself.

logrusorgru avatar Oct 06 '22 04:10 logrusorgru

Feature included in #26. Thank you.

logrusorgru avatar Oct 08 '22 11:10 logrusorgru