Sha256: 0432d9b10c7a8b63d5794a2a6bfeb89f7e34379d9f5edce5ff859397d6357e73

Contents?: true

Size: 804 Bytes

Versions: 5

Compression:

Stored size: 804 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 message.to_s.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

5 entries across 5 versions & 1 rubygems

Version Path
git_commands-3.2.4 lib/git_commands/prompt.rb
git_commands-3.2.3 lib/git_commands/prompt.rb
git_commands-3.2.2 lib/git_commands/prompt.rb
git_commands-3.2.1 lib/git_commands/prompt.rb
git_commands-3.2.0 lib/git_commands/prompt.rb