Class: TTY::Link::ANSILink Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/link/ansi_link.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for converting a URL to an ANSI-controlled terminal link

Instance Method Summary collapse

Constructor Details

#initialize(name, url, attrs) ⇒ ANSILink

Create an TTY::Link::ANSILink instance

Examples:

ansi_link = TTY::Link::ANSILink.new(
  "TTY Toolkit", "https://ttytoolkit.org", {id: "tty-toolkit"})

Parameters:

  • name (String)

    the URL name

  • url (String)

    the URL target

  • attrs (Hash{Symbol => String})

    the URL attributes



63
64
65
66
67
# File 'lib/tty/link/ansi_link.rb', line 63

def initialize(name, url, attrs)
  @name = name
  @url = url
  @attrs = attrs
end

Instance Method Details

#to_sString

Convert this link to an ANSI-controlled string

Examples:

ansi_link.to_s
# => "\e]8;id=tty-toolkit;https://ttytoolkit.org\aTTY Toolkit\e]8;;\a"

Returns:

  • (String)


78
79
80
81
# File 'lib/tty/link/ansi_link.rb', line 78

def to_s
  attributes = convert_to_attributes(@attrs)
  [OSC8, SEP, attributes, SEP, @url, BEL, @name, OSC8, SEP, SEP, BEL].join
end