Sha256: 6b39ae6cba7780a69bf19ebec1059918d242ab96915a6d25f47364265bed4df8

Contents?: true

Size: 1.39 KB

Versions: 46

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Appsignal
  class CLI
    module Helpers
      private

      def colorize(text, color)
        return text if Gem.win_platform?

        color_code =
          case color
          when :red then 31
          when :green then 32
          when :yellow then 33
          when :blue then 34
          when :pink then 35
          else 0
          end

        "\e[#{color_code}m#{text}\e[0m"
      end

      def periods
        3.times do
          print "."
          sleep 0.5
        end
      end

      def press_any_key
        puts
        print "  Ready? Press any key:"
        stdin.getc
        puts
        puts
      end

      def ask_for_input
        value = stdin.gets
        value ? value.chomp : ""
      rescue Interrupt
        puts "\nExiting..."
        exit 1
      end

      def required_input(prompt)
        loop do
          print prompt
          value = ask_for_input
          return value unless value.empty?
        end
      end

      def yes_or_no(prompt, options = {})
        loop do
          print prompt
          input = ask_for_input.strip
          input = options[:default] if input.empty? && options[:default]
          case input
          when "y", "Y", "yes"
            return true
          when "n", "N", "no"
            return false
          end
        end
      end

      def stdin
        $stdin
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
appsignal-2.8.4 lib/appsignal/cli/helpers.rb
appsignal-2.8.4-java lib/appsignal/cli/helpers.rb
appsignal-2.8.4.beta.1 lib/appsignal/cli/helpers.rb
appsignal-2.8.4.beta.1-java lib/appsignal/cli/helpers.rb
appsignal-2.8.3 lib/appsignal/cli/helpers.rb
appsignal-2.8.3-java lib/appsignal/cli/helpers.rb
appsignal-2.8.3.beta.1 lib/appsignal/cli/helpers.rb
appsignal-2.8.3.beta.1-java lib/appsignal/cli/helpers.rb
appsignal-2.8.2 lib/appsignal/cli/helpers.rb
appsignal-2.8.2-java lib/appsignal/cli/helpers.rb
appsignal-2.8.1 lib/appsignal/cli/helpers.rb
appsignal-2.8.1-java lib/appsignal/cli/helpers.rb
appsignal-2.8.1.alpha.1-java lib/appsignal/cli/helpers.rb
appsignal-2.8.1.alpha.1 lib/appsignal/cli/helpers.rb
appsignal-2.8.0 lib/appsignal/cli/helpers.rb
appsignal-2.8.0-java lib/appsignal/cli/helpers.rb
appsignal-2.7.3.beta.2-java lib/appsignal/cli/helpers.rb
appsignal-2.7.3.beta.2 lib/appsignal/cli/helpers.rb
appsignal-2.7.3.beta.1 lib/appsignal/cli/helpers.rb
appsignal-2.7.3.beta.1-java lib/appsignal/cli/helpers.rb