Sha256: 6a41ced5e505b259974655062423b47988e70130cbcf0c852b3d97ad5264f8d6

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

module JazzFingers
  class Prompt
    def initialize(options = {})
      @colored = options.fetch(:colored)
      @separator = options.fetch(:separator)
      @application_name = options.fetch(:application_name)
    end

    def colored?
      @colored
    end

    def red_text(text)
      return text.to_s unless colored?

      "\001\e[0;31m\002#{text}\001\e[0m\002"
    end

    def blue_text(text)
      return text.to_s unless colored?

      "\001\e[0;34m\002#{text}\001\e[0m\002"
    end

    def bold_text(text)
      return text.to_s unless colored?

      "\001\e[1m\002#{text}\001\e[0m\002"
    end

    def separator
      red_text(@separator)
    end

    def name
      blue_text(@application_name)
    end

    def line_number(pry)
      "[#{bold_text(pry.input_array.size)}]"
    end

    def text(object, level)
      level = 0 if level < 0
      text = Pry.view_clip(object)

      if text == "main"
        ""
      else
        "(#{'../' * level}#{text})"
      end
    end

    def main_prompt
      lambda do |_object, _level, pry|
        "#{RUBY_VERSION} #{name}#{line_number(pry)} #{separator} "
      end
    end

    def block_prompt
      lambda do |_object, level, pry|
        spaces = "  " * level
        "#{RUBY_VERSION} #{name}#{line_number(pry)} * #{spaces}"
      end
    end

    def config
      [main_prompt, block_prompt]
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jazz_fingers-4.0.1 lib/jazz_fingers/prompt.rb
jazz_fingers-4.0.0 lib/jazz_fingers/prompt.rb
jazz_fingers-3.0.2 lib/jazz_fingers/prompt.rb
jazz_fingers-3.0.1 lib/jazz_fingers/prompt.rb
jazz_fingers-3.0.0 lib/jazz_fingers/prompt.rb
jazz_fingers-2.0.2 lib/jazz_fingers/prompt.rb
jazz_fingers-2.0.2.rc1 lib/jazz_fingers/prompt.rb
jazz_fingers-2.0.1 lib/jazz_fingers/prompt.rb
jazz_fingers-2.0.1.rc1 lib/jazz_fingers/prompt.rb