savioxavier / termlink

Clickable links in the terminal for Go
https://pkg.go.dev/github.com/savioxavier/termlink
MIT License
64 stars 2 forks source link
cli command-line go golang golang-package hacktoberfest hyperlink sindresorhus terminal terminal-color termlink windows-terminal

termlink

Clickable links in the terminal for Go

Release Go Reference License Go Report Card

termlink_demo_nyoom *

Termlink is a Go package that allows you to create fully customizable clickable links in the terminal. It is the Go version of Sindre Sorhus' popular terminal-link library.

It includes multiple features including dynamic and fully customizable colored links in terminal, along with smart hyperlink support detection.

๐Ÿ› ๏ธ Install

Using go get:

go get github.com/savioxavier/termlink

๐Ÿ”— Usage

import (
    "fmt"

    "github.com/savioxavier/termlink"
)

func main() {
    fmt.Println(termlink.Link("Example", "https://example.com"))
}
import (
    "fmt"

    "github.com/savioxavier/termlink"
)

func main() {
    fmt.Println(termlink.ColorLink("Example", "https://example.com", "italic green"))
}
import (
    "fmt"

    "github.com/savioxavier/termlink"
)

func main() {
    fmt.Println(termlink.SupportsHyperlinks())
    // prints either true or false, depending on your terminal
}
import (
    "fmt"

    "github.com/fatih/color"
    "github.com/savioxavier/termlink"
)

func main() {
    // With fatih/color package
    color.Cyan(termlink.Link("Example link using the fatih/color package", "https://example.com"))
}

Note For unsupported terminals, the link will be printed in parentheses after the text (see below image)

image


๐Ÿต Examples

More examples can be found in the examples/ directory.

For a quick demo, execute the following commands in your terminal:

git clone https://github.com/savioxavier/termlink.git
cd termlink/
go get github.com/savioxavier/termlink
go run examples/start.go

๐Ÿ”ฎ Features

shouldForce can be used in the following manner:

termlink.Link(text, url, true)
termlink.ColorLink(text, url, color, true)

You don't always need to specify this argument. By default, this parameter is false


๐Ÿงช Tests

You can run unit tests locally by running the following command:

go test -v

Tests can be found in termlink_test.go


โค๏ธ Support

You can support further development of this project by giving it a ๐ŸŒŸ and help me make even better stuff in the future by buying me a โ˜•


Also, if you liked this repo, consider checking out my other projects, that would be real cool!


๐Ÿ’ซ Attributions and special thanks

* The paperclip icon shown in the demo at the top of this README isn't included when you create the link, it's purely for decorative purposes only.