Sha256: aca4b7b876f2e50318e348cea832eef9babf4b12ba91a08ca1ab7460d858cfe7

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

module PryTheme
  module Helper

    module_function

    def example_themes
      (Dir.entries(EXAMPLES_ROOT) - %w{ . .. })
    end

    def installed_themes
      (Dir.entries(THEME_DIR) - %w{ . .. })
    end

    def installed?(theme)
      installed_themes.any? { |t| /\A#{theme}.prytheme\z/ =~ t }
    end

    def lputs(text, out=nil)
      Pry::Helpers::BaseHelpers.stagger_output(text, out)
    end

    def make_bold(text)
      Pry::Helpers::Text.bold(text)
    end

    def theme_file_version(path)
      version = File.foreach(path) { |line| break line if $. == 4 }
      version.scan(/\d+/)[0].to_i
    end

    def default_theme(name)
      File.join(EXAMPLES_ROOT, name)
    end

    def local_theme(name)
      File.join(THEME_DIR, name)
    end

    def pathify_theme(name)
      File.join(THEME_DIR, "#{ name }.prytheme")
    end

    def fetch_collection(path, &block)
      uri = URI.parse(COLLECTION + path)
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true

      yield(http, uri)
    end

    def ansi?(color)
      if color.to_s =~ /\A(\d{1,3})\z/
        (0..255).include?(color.to_i)
      else
        false
      end
    end

    def rgb?(color)
      rgb_pattern = /
                      \A

                      ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
                      ,
                      ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
                      ,
                      ([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])

                      \z
                    /x
      color =~ rgb_pattern ? true : false
    end

    def hex?(color)
      color =~ /\A#?[A-F\d]{6}\z/i ? true : false
    end

    def display_header(text, out)
      safe_width = 80

      out.puts "-" * safe_width
      out.puts make_bold(text.center(safe_width))
      out.puts "-" * safe_width
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pry-theme-0.1.3 lib/pry-theme/helper.rb
pry-theme-0.1.2 lib/pry-theme/helper.rb
pry-theme-0.1.1 lib/pry-theme/helper.rb
pry-theme-0.1.0 lib/pry-theme/helper.rb