Class: TTY::Link
- Inherits:
-
Object
- Object
- TTY::Link
- Defined in:
- lib/tty/link.rb,
lib/tty/link/errors.rb,
lib/tty/link/version.rb,
lib/tty/link/ansi_link.rb,
lib/tty/link/terminals.rb,
lib/tty/link/plain_link.rb,
lib/tty/link/terminals/wt.rb,
lib/tty/link/terminals/rio.rb,
lib/tty/link/terminals/vte.rb,
lib/tty/link/terminals/foot.rb,
lib/tty/link/terminals/hyper.rb,
lib/tty/link/terminals/iterm.rb,
lib/tty/link/terminals/kitty.rb,
lib/tty/link/terminals/tabby.rb,
lib/tty/link/semantic_version.rb,
lib/tty/link/terminals/mintty.rb,
lib/tty/link/terminals/vscode.rb,
lib/tty/link/terminals/contour.rb,
lib/tty/link/terminals/domterm.rb,
lib/tty/link/terminals/konsole.rb,
lib/tty/link/terminals/wezterm.rb,
lib/tty/link/terminals/abstract.rb,
lib/tty/link/terminals/jediterm.rb,
lib/tty/link/hyperlink_parameter.rb,
lib/tty/link/terminals/alacritty.rb,
lib/tty/link/terminals/terminology.rb
Overview
Responsible for detecting and generating terminal hyperlinks
Defined Under Namespace
Modules: Terminals Classes: ANSILink, AbstractMethodError, HyperlinkParameter, PlainLink, SemanticVersion, ValueError
Constant Summary collapse
- Error =
Raised to signal an error condition
Class.new(StandardError)
- VERSION =
"0.2.0"
Class Method Summary collapse
-
.link?(env: ENV, output: $stdout) ⇒ Boolean
Detect terminal hyperlink support.
-
.link_to(name, url = nil, attrs: {}, env: ENV, hyperlink: :auto, output: $stdout, plain: DEFAULT_TEMPLATE) ⇒ String
Generate terminal hyperlink.
Instance Method Summary collapse
-
#initialize(env: ENV, hyperlink: :auto, output: $stdout, plain: DEFAULT_TEMPLATE) ⇒ Link
constructor
Create a Link instance.
-
#link? ⇒ Boolean
Detect terminal hyperlink support.
-
#link_to(name, url = nil, attrs: {}) ⇒ String
Generate terminal hyperlink.
Constructor Details
#initialize(env: ENV, hyperlink: :auto, output: $stdout, plain: DEFAULT_TEMPLATE) ⇒ Link
Create a TTY::Link instance
141 142 143 144 145 146 147 |
# File 'lib/tty/link.rb', line 141 def initialize(env: ENV, hyperlink: :auto, output: $stdout, plain: DEFAULT_TEMPLATE) @env = env @hyperlink_parameter = hyperlink_parameter(hyperlink_env || hyperlink) @output = output @plain = plain end |
Class Method Details
.link?(env: ENV, output: $stdout) ⇒ Boolean
Detect terminal hyperlink support
110 111 112 |
# File 'lib/tty/link.rb', line 110 def self.link?(env: ENV, output: $stdout) new(env: env, output: output).link? end |
.link_to(name, url = nil, attrs: {}, env: ENV, hyperlink: :auto, output: $stdout, plain: DEFAULT_TEMPLATE) ⇒ String
Generate terminal hyperlink
80 81 82 83 84 |
# File 'lib/tty/link.rb', line 80 def self.link_to(name, url = nil, attrs: {}, env: ENV, hyperlink: :auto, output: $stdout, plain: DEFAULT_TEMPLATE) new(env: env, hyperlink: hyperlink, output: output, plain: plain) .link_to(name, url, attrs: attrs) end |
Instance Method Details
#link? ⇒ Boolean
Detect terminal hyperlink support
194 195 196 197 198 |
# File 'lib/tty/link.rb', line 194 def link? return false unless tty? terminals.any?(&:link?) end |
#link_to(name, url = nil, attrs: {}) ⇒ String
Generate terminal hyperlink
175 176 177 178 179 180 181 182 183 |
# File 'lib/tty/link.rb', line 175 def link_to(name, url = nil, attrs: {}) url ||= name if ansi_link? ansi_link(name, url, attrs).to_s else plain_link(name, url).to_s end end |