Module: Yildun::Links

Defined in:
lib/yildun/links.rb,
sig/yildun.rbs

Class Method Summary collapse

Class Method Details

.at(screen, row, column, cwd: Dir.pwd) ⇒ Hash[Symbol, untyped]?

Parameters:

  • screen (Object)
  • row (Integer)
  • column (Integer)
  • cwd: (String) (defaults to: Dir.pwd)

Returns:

  • (Hash[Symbol, untyped], nil)


7
8
9
10
# File 'lib/yildun/links.rb', line 7

def at(screen, row, column, cwd: Dir.pwd)
  screen.links(row).find { |link| column.between?(link[:column], link[:end_column] - 1) } ||
    screen.file_paths(row, cwd: cwd).find { |link| column == link[:column] }
end

.open(url, opener: nil) ⇒ Object

Parameters:

  • url (String)
  • opener: (^(String) -> untyped) (defaults to: nil)

Returns:

  • (Object)

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/yildun/links.rb', line 12

def open(url, opener: nil)
  raise ArgumentError, "only http(s) and mailto links are allowed" unless url.to_s.match?(/\A(?:https?|mailto):/i)
  return opener.call(url) if opener
  command = RUBY_PLATFORM.match?(/darwin/) ? "open" : "xdg-open"
  Process.spawn(command, url.to_s, out: File::NULL, err: File::NULL)
end