Skip to content

Commit

Permalink
Added termlink builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Casabianca committed Sep 5, 2024
1 parent a9224b2 commit a32ddba
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions neon/builtin/termlink.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package builtin

import (
"github.com/c4s4/neon/neon/build"
)

func init() {
build.AddBuiltin(build.BuiltinDesc{
Name: "termlink",
Func: termlink,
Help: `Make given string a link when printed in a terminal.
Arguments:
- The URL to link to.
- The text to print on terminal.
Note: if text is empty, the URL is used as text.
Examples:
# make link for string "Example" to "https://example.com"
termlink("https://example.com", "Example")
# returns: string "Example" with escape codes for terminal link to "https://example.com"`,
})
}

func termlink(url, text string) string {
if text == "" {
text = url
}
return "\033]8;;" + url + "\033\\" + text + "\033]8;;\033\\"
}

0 comments on commit a32ddba

Please sign in to comment.