savioxavier / termlink Goto Github PK
View Code? Open in Web Editor NEWClickable links in the terminal for Go
Home Page: https://pkg.go.dev/github.com/savioxavier/termlink
License: MIT License
Clickable links in the terminal for Go
Home Page: https://pkg.go.dev/github.com/savioxavier/termlink
License: MIT License
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.
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?
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?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.