Sha256: 57dbb13f835e3690113af9abe1040b36b6f7d0a8acdb391d4bb7b7a546eea5d9

Contents?: true

Size: 945 Bytes

Versions: 8

Compression:

Stored size: 945 Bytes

Contents

require 'tins/terminal'

module Term
  module ANSIColor
    module Hyperlink
      def hyperlink(link, string = nil, id: nil, as_link: false)
        block_given? && string != nil && !respond_to?(:to_str) and
          raise ArgumentError,
          "Require either the string argument or a block argument"
        if link.nil?
          link = ''
        end
        if as_link && !link.empty?
          string ||= link
        end
        result = ''
        if Term::ANSIColor.coloring?
          result = "\e]8;#{"id=#{id}" unless id.nil?};" << link.to_str << "\e\\"
        end
        if block_given?
          result << yield.to_s
        elsif string.respond_to?(:to_str)
          result << string.to_str
        elsif respond_to?(:to_str)
          result << to_str
        else
          return result # only switch on
        end
        result << "\e]8;;\e\\" if Term::ANSIColor.coloring?
        result
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
term-ansicolor-1.11.0 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.10.4 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.10.3 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.10.2 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.10.1 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.10.0 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.9.0 lib/term/ansicolor/hyperlink.rb
term-ansicolor-1.8.0 lib/term/ansicolor/hyperlink.rb