{"id":22327141,"url":"https://github.com/piotrmurach/tty-link","last_synced_at":"2025-04-05T18:08:32.308Z","repository":{"id":59158173,"uuid":"201645833","full_name":"piotrmurach/tty-link","owner":"piotrmurach","description":"Terminal hyperlinks support detection and generation.","archived":false,"fork":false,"pushed_at":"2024-11-03T17:56:44.000Z","size":171,"stargazers_count":42,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T17:09:31.911Z","etag":null,"topics":["alacritty","contour","gnome-terminal","hyperlink","hyperlink-support","iterm2","kde-konsole","kitty","mintty","ruby","rubygem","terminal","terminology","tty","tty-components","vscode-terminal","wezterm","windows-terminal"],"latest_commit_sha":null,"homepage":"https://ttytoolkit.org","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piotrmurach.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"piotrmurach"}},"created_at":"2019-08-10T15:08:34.000Z","updated_at":"2025-02-05T12:46:06.000Z","dependencies_parsed_at":"2024-04-07T19:31:26.801Z","dependency_job_id":"a113c4bb-33b8-4dd2-b59b-8b1baa26efcb","html_url":"https://github.com/piotrmurach/tty-link","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"fd6a5f530c53c9eb80ff588f44ddad8b733dfc52"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Ftty-link","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Ftty-link/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Ftty-link/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Ftty-link/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotrmurach","download_url":"https://codeload.github.com/piotrmurach/tty-link/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378144,"owners_count":20929296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alacritty","contour","gnome-terminal","hyperlink","hyperlink-support","iterm2","kde-konsole","kitty","mintty","ruby","rubygem","terminal","terminology","tty","tty-components","vscode-terminal","wezterm","windows-terminal"],"created_at":"2024-12-04T03:08:27.715Z","updated_at":"2025-04-05T18:08:32.288Z","avatar_url":"https://github.com/piotrmurach.png","language":"Ruby","funding_links":["https://github.com/sponsors/piotrmurach"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://ttytoolkit.org\"\u003e\u003cimg width=\"130\" src=\"https://github.com/piotrmurach/tty/raw/master/images/tty.png\" alt=\"TTY Toolkit logo\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n# TTY::Link\n\n[![Gem Version](https://badge.fury.io/rb/tty-link.svg)][gem]\n[![Actions CI](https://github.com/piotrmurach/tty-link/actions/workflows/ci.yml/badge.svg)][gh_actions_ci]\n[![Build status](https://ci.appveyor.com/api/projects/status/4vb3w6wmr9w9vfp7?svg=true)][appveyor]\n[![Maintainability](https://api.codeclimate.com/v1/badges/3f8c368617c464238bf9/maintainability)][codeclimate]\n[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-link/badge.svg)][coverage]\n\n[gem]: https://badge.fury.io/rb/tty-link\n[gh_actions_ci]: https://github.com/piotrmurach/tty-link/actions/workflows/ci.yml\n[appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-link\n[codeclimate]: https://codeclimate.com/github/piotrmurach/tty-link/maintainability\n[coverage]: https://coveralls.io/github/piotrmurach/tty-link\n\n\u003e Terminal hyperlinks support detection and generation.\n\n**TTY::Link** detects whether the terminal supports hyperlinks and creates them\nready for display in the console. It is a component of the\n[TTY toolkit](https://github.com/piotrmurach/tty).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"tty-link\"\n```\n\nAnd then execute:\n\n```shell\n$ bundle\n```\n\nOr install it yourself as:\n\n```shell\n$ gem install tty-link\n```\n\n## Contents\n\n* [1. Usage](#1-usage)\n* [2. API](#2-api)\n  * [2.1 new](#21-new)\n    * [2.1.1 :env](#211-env)\n    * [2.1.2 :output](#212-output)\n    * [2.1.3 :hyperlink](#213-hyperlink)\n    * [2.1.4 :plain](#214-plain)\n  * [2.2 link?](#22-link)\n  * [2.3 link_to](#23-link_to)\n    * [2.3.1 :attrs](#231-attrs)\n* [3. Supported Terminals](#3-supported-terminals)\n\n## 1. Usage\n\nCreate a **TTY::Link** instance:\n\n```ruby\nlink = TTY::Link.new\n```\n\nThen use the [link_to](#23-link_to) method to print a hyperlink in the terminal:\n\n```ruby\nputs link.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\")\n```\n\nThis will output a clickable link in the\n[terminal supporting](#3-supported-terminals) hyperlinks:\n\n```shell\nTTY Toolkit\n```\n\nOr it will print a [plain](#214-plain) text version with a URL in unsupported\nterminals:\n\n```shell\nTTY Toolkit -\u003e https://ttytoolkit.org\n```\n\nBy default, **TTY::Link** uses the [link?](#22-link) method to detect whether\nthe terminal supports hyperlinks:\n\n```ruby\nlink.link?\n```\n\nOverwrite this automatic detection with the [:hyperlink](#213-hyperlink)\nkeyword.\n\nFor example, to always create hyperlinks in the terminal:\n\n```ruby\nlink = TTY::Link.new(hyperlink: :always)\n```\n\nAlternatively, use the `TTY_LINK_HYPERLINK` environment variable to control\nhyperlink support detection. The variable takes precedence over the\n[:hyperlink](#213-hyperlink) keyword.\n\nUse the [:env](#211-env) keyword to overwrite any environment variables set\nin the terminal:\n\n```ruby\nlink = TTY::Link.new(env: {\"TTY_LINK_HYPERLINK\" =\u003e \"always\"})\n```\n\nAs a convenience, the [link?](#22-link) and [link_to](#23-link_to) methods\nare also available on the **TTY::Link** class. The methods accept all the\nconfiguration keywords.\n\nFor example, to always output hyperlinks in the terminal:\n\n```ruby\nputs TTY::Link.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\", hyperlink: :always)\n```\n\n## 2. API\n\n### 2.1 new\n\n#### 2.1.1 :env\n\nThe `new` method accepts the `:env` keyword to define environment variables.\nThe keyword defaults to the `ENV` object that holds the current environment\nvariables.\n\nFor example, to define only an environment variable `TTY_LINK_HYPERLINK` with\n`always` value:\n\n```ruby\nlink = TTY::Link.new(env: {\"TTY_LINK_HYPERLINK\" =\u003e \"always\"})\n```\n\n#### 2.1.2 :output\n\nThe `new` method accepts the `:output` keyword to define the output stream. The\nkeyword defaults to the standard output.\n\nFor example, to use the standard error stream:\n\n```ruby\nlink = TTY::Link.new(output: $stderr)\n```\n\n#### 2.1.3 :hyperlink\n\nThe `new` method accepts the `:hyperlink` keyword to control terminal hyperlink\nsupport detection. The available values are `:always`, `:auto` and `:never`. The\nkeyword defaults to the `:auto` value to allow the [link?](#22-link) method\nto check whether the given terminal supports hyperlinks.\n\nFor example, use the `:always` value to force the [link_to](#23-link_to) method\nto create hyperlinks without checking terminal support:\n\n```ruby\nlink = TTY::Link.new(hyperlink: :always)\n```\n\nOr, use the `:never` value to force the [link_to](#23-link_to) to create\ntext-only links:\n\n```ruby\nlink = TTY::Link.new(hyperlink: :never)\n```\n\nAlternatively, set the `TTY_LINK_HYPERLINK` environment variable to configure\nthe `:hyperlink` value:\n\n```shell\nTTY_LINK_HYPERLINK=always\n```\n\n#### 2.1.4 :plain\n\nThe `new` method accepts the `:plain` keyword to define a text-only hyperlink\nreplacement template. The [link_to](#23-link_to) method uses the template to\ncreate a plain URL alternative on terminals without hyperlink support.\n\nThe template can contain two tokens, the `:name` and the `:url`. The tokens\nare optional. The `:name -\u003e :url` is the default template. The\n[link_to](#23-link_to) method replaces the present token with the given\nargument.\n\nFor example, given a link to `https://ttytoolkit.org` named `TTY Toolkit`:\n\n```ruby\nlink.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\")\n```\n\nThis will create the following string from the default template:\n\n```ruby\n\"TTY toolkit -\u003e https://ttytoolkit.org\"\n```\n\nTo change the default template and display links, for example, with the name\nand the URL surrounded by brackets:\n\n```ruby\nlink = TTY::Link.new(plain: \":name (:url)\")\n```\n\nThen passing the same arguments to the [link_to](#23-link_to) method:\n\n```ruby\nlink.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\")\n```\n\nThis will create the following string from the custom template:\n\n```ruby\n\"TTY toolkit (https://ttytoolkit.org)\"\n```\n\n### 2.2 link?\n\nThe `link?` method detects whether the terminal supports hyperlinks against\n[supported terminals](#3-supported-terminals). The [link_to](#23-link_to)\nmethod uses this detection to decide whether to create a hyperlink or plain\ntext alternative.\n\nFor example, to check the current terminal hyperlink support:\n\n```ruby\nlink.link?\n```\n\n### 2.3 link_to\n\nThe `link_to` method accepts two arguments, the name and the URL. The second\nURL argument is optional.\n\nFor example, to create a hyperlink to `https://ttytoolkit.org`\nnamed `TTY Toolkit`:\n\n```ruby\nlink.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\")\n```\n\nTo create a hyperlink where the name is the same as the URL:\n\n```ruby\nlink.link_to(\"https://ttytoolkit.org\")\n```\n\n#### 2.3.1 :attrs\n\nThe `link_to` method accepts the `:attrs` keyword to define attributes for a\nhyperlink. Note that currently, hyperlink-capable terminals support only the\n`id` attribute. However, there is no limitation on the attribute names to\nallow future support.\n\nFor example, to define the `id` attribute:\n\n```ruby\nlink.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\", attrs: {id: \"tty-toolkit\"})\n```\n\nTo define many attributes such as `id`, `lang` and `title`:\n\n```ruby\nlink.link_to(\"TTY Toolkit\", \"https://ttytoolkit.org\", attrs: {\n  id: \"tty-toolkit\", lang: \"en\", title: \"Terminal Apps The Easy Way\"\n})\n```\n\n## 3. Supported Terminals\n\nThe **TTY::Link** supports hyperlink generation in the following terminals:\n\n* `Alacritty`\n* `Contour`\n* `DomTerm`\n* `foot`\n* `Hyper`\n* `iTerm2`\n* `JediTerm`\n* `kitty`\n* `Konsole`\n* `mintty`\n* `Rio`\n* `Tabby`\n* `Terminology`\n* `VSCode`\n* `VTE (GNOME, Xfce, ROXTerm, Guake, sakura, Terminator)`\n* `WezTerm`\n* `Windows Terminal`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies.\nThen, run `rake spec` to run the tests. You can also run `bin/console`\nfor an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\nTo release a new version, update the version number in `version.rb`, and then\nrun `bundle exec rake release`, which will create a git tag for the version,\npush git commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/piotrmurach/tty-link.\nThis project is intended to be a safe, welcoming space for collaboration,\nand contributors are expected to adhere to the\n[code of conduct](https://github.com/piotrmurach/tty-link/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the TTY::Link project’s codebases, issue trackers,\nchat rooms and mailing lists is expected to follow the\n[code of conduct](https://github.com/piotrmurach/tty-link/blob/master/CODE_OF_CONDUCT.md).\n\n## Copyright\n\nCopyright (c) 2019 Piotr Murach. See\n[LICENSE.txt](https://github.com/piotrmurach/tty-link/blob/master/LICENSE.txt)\nfor further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Ftty-link","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotrmurach%2Ftty-link","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Ftty-link/lists"}