Giter Site home page Giter Site logo

savioxavier / termlink Goto Github PK

View Code? Open in Web Editor NEW
59.0 2.0 0.0 76 KB

Clickable links in the terminal for Go

Home Page: https://pkg.go.dev/github.com/savioxavier/termlink

License: MIT License

Go 100.00%
go golang golang-package hyperlink sindresorhus terminal terminal-color windows-terminal termlink cli

termlink's Issues

Write unit tests

Description

Unit tests need to be written for this package - using a mixture of the assert package from stretchr/testify and Go's native testing library.

The tests need to support both hyperlink supporting and non-hyperlink supporting terminals, by using this package's SupportsHyperlinks() method. A basic test would look something like this:

func TestBasicLink(t *testing.T) {
	if termlink.SupportsHyperlinks() {
		assert.Equal(t, termlink.Link("Hello", "https://google.com"), "\x1b]8;;https://google.com\aHello\x1b]8;;\a\x1b[m")
	} else {
		assert.Equal(t, termlink.Link("Hello", "https://google.com"), "Hello (\u200Bhttps://google.com)\u001b[m")
	}
}
go test -v

The tests would need to be run in both terminals - one that supports hyperlinks, and one that doesn't. I'll be using a few AI assisted tools to speed up testing. A few basic tests would do fine as of now, more tests can be added later.

If all the tests work as expected, then it's all good to go!

Assigning this issue to myself. Should be an easy enough job.

Support alacritty

Hi Im about to use this library for a project of mine. I have tested in and discovered that alacritty is currently not supported. Alacritty supports an URL behaviour similar to other terminals:

echo -e '\e]8;;http://example.com\aThis is a link\e]8;;\a'

Possible to support this. So far I havent seen any Env var that alacritty sets that we can use to detect the users terminal. Maybe I will provide a PR if I have an Idea.

Btw, you aware of this list https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda?

Extra space after the opening paren

In Terminals which do not support linking, there is an extra space after the opening paren.

Code:

fmt.Sprintf("%s", termlink.Link("RE2 syntax", "https://github.com/google/re2/wiki/Syntax"))

Display in Apple's Terminal.app (which does not support linking):

RE2 syntax ( ​https://github.com/google/re2/wiki/Syntax)

What's weird is that when I copy-paste it from the Terminal, the paste here in GitHub doesn't have it.

RE2 syntax (​https://github.com/google/re2/wiki/Syntax)

Any ideas?

Force non-linking behavior?

I'm building a CLI app that has the ability to generate usage documentation for itself as Markdown.

Under normal circumstances — e.g., using the CLI on terminal — I want the linking behavior, which works.

However, when I generate Markdown containing the descriptions of the CLI commands (which contain the links), I get the raw ASCII output for the terminal.

For regular expressions, the �[32;49m�]8;;https://github.com/google/re2/wiki/Syntax�RE2 syntax�]8;;��[m�[0m is supported.

What I'd like to have is something that would allow me to programmatically force the non-linked behavior, so that the Markdown has this instead.

For regular expressions, the RE2 syntax (https://github.com/google/re2/wiki/Syntax) is supported.

I can do it by running the generation command in a completely different terminal (e.g., Apple's Terminal.app), but it'd be nice if I didn't have to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.