Sha256: 3f1b7dc5ab94c82905969c120554dcb66f5969af6d17b270f707f02c1a35f464

Contents?: true

Size: 1.78 KB

Versions: 151

Compression:

Stored size: 1.78 KB

Contents

module Danger
  class Interviewer
    attr_accessor :no_delay, :no_waiting, :ui

    def initialize(cork_board)
      @ui = cork_board
    end

    def show_prompt
      ui.print "> ".bold.green
    end

    def yellow_bang
      "! ".yellow
    end

    def green_bang
      "! ".green
    end

    def red_bang
      "! ".red
    end

    def say(output)
      ui.puts output
    end

    def header(title)
      say title.yellow
      say ""
      pause 0.6
    end

    def link(url)
      say " -> " + url.underlined + "\n"
    end

    def pause(time)
      sleep(time) unless @no_waiting
    end

    def wait_for_return
      STDOUT.flush
      STDIN.gets unless @no_delay
      ui.puts
    end

    def run_command(command, output_command = nil)
      output_command ||= command
      ui.puts "  " + output_command.magenta
      system command
    end

    def ask_with_answers(question, possible_answers)
      ui.print "\n#{question}? ["

      print_info = proc do
        possible_answers.each_with_index do |answer, i|
          the_answer = i.zero? ? answer.underlined : answer
          ui.print " " + the_answer
          ui.print(" /") if i != possible_answers.length - 1
        end
        ui.print " ]\n"
      end
      print_info.call

      answer = ""

      loop do
        show_prompt
        answer = @no_waiting ? possible_answers[0].downcase : STDIN.gets.downcase.chomp

        answer = "yes" if answer == "y"
        answer = "no" if answer == "n"

        # default to first answer
        if answer == ""
          answer = possible_answers[0].downcase
          ui.puts "Using: " + answer.yellow
        end

        break if possible_answers.map(&:downcase).include? answer

        ui.print "\nPossible answers are ["
        print_info.call
      end

      answer
    end
  end
end

Version data entries

151 entries across 151 versions & 2 rubygems

Version Path
danger-additional-logging-0.0.23 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.22 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.21 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.20 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.19 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.18 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.17 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.16 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.15 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.14 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.13 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.12 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.11 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.10 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.9 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.8 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.7 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.6 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.5 lib/danger/commands/init_helpers/interviewer.rb
danger-additional-logging-0.0.4 lib/danger/commands/init_helpers/interviewer.rb