Class: TerminalLink::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal_link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, text = nil) ⇒ Link

Returns a new instance of Link.



5
6
7
8
# File 'lib/terminal_link.rb', line 5

def initialize(url=nil, text=nil)
  @text = text
  @url = url
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/terminal_link.rb', line 3

def text
  @text
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/terminal_link.rb', line 3

def url
  @url
end

Instance Method Details



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/terminal_link.rb', line 10

def print
  # template = "echo -e '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\'"
  default_link = "https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda"
  if url && !text
    system("echo", "\e]8;;#{@url}\e\\#{@url}\e]8;;\e\\")
  elsif url && text
    system("echo", "\e]8;;#{@url}\e\\#{@text}\e]8;;\e\\")
  elsif !url && !text
    system("echo", "\e]8;;#{default_link}\e\\Hyperlinks in terminal emulators\e]8;;\e\\")
    #`echo -e '\e]8;;#{default_link}}\e\\"Hyperlinks in terminal emulators\e]8;;\e\\'`
  end
end