Sha256: 8078c47c37c66604245ad3be4bc34e9d917f1ba4e36ce5f0134925eceb02ab90

Contents?: true

Size: 803 Bytes

Versions: 3

Compression:

Stored size: 803 Bytes

Contents

require "git_commands/colorize"

module GitCommands
  using Colorize
  module Prompt
    VALID_ANSWERS = %w[Y y N n]

    class AbortError < StandardError; end

    def out
      @out ||= STDOUT
    end

    def warning(message)
      out.puts "\n#{message}".yellow
    end

    def success(message)
      out.puts "\n#{message}".green
      true
    end

    def confirm(message)
      res = begin
        ask "#{message} (Y/N)?"
      end until VALID_ANSWERS.include?(res)
      case res
      when /y/i
        yield
      else
        fail(AbortError, "Aborted operation!")
      end
    end

    def error(message)
      out.puts message.to_s.red
    end

    private def ask(message)
      out.print message.cyan
      input
    end

    private def input
      STDIN.gets.chomp
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git_commands-3.5.3 lib/git_commands/prompt.rb
git_commands-3.5.2 lib/git_commands/prompt.rb
git_commands-3.5.1 lib/git_commands/prompt.rb