Sha256: 9304854b1d9bc7b0da68199dbed1a7e2f357585bcadf93e762fb4bf19f4be14a

Contents?: true

Size: 1.7 KB

Versions: 136

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require "appsignal/utils/rails_helper"

module Appsignal
  class CLI
    module Helpers
      private

      COLOR_CODES = {
        :red => 31,
        :green => 32,
        :yellow => 33,
        :blue => 34,
        :pink => 35,
        :default => 0
      }.freeze

      def coloring=(value)
        @coloring = value
      end

      def coloring?
        return true unless defined?(@coloring)

        @coloring
      end

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

        reset_color_code = COLOR_CODES.fetch(:default)
        color_code = COLOR_CODES.fetch(color, reset_color_code)

        "\e[#{color_code}m#{text}\e[#{reset_color_code}m"
      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

136 entries across 136 versions & 1 rubygems

Version Path
appsignal-4.2.0-java lib/appsignal/cli/helpers.rb
appsignal-4.2.0 lib/appsignal/cli/helpers.rb
appsignal-4.1.3-java lib/appsignal/cli/helpers.rb
appsignal-4.1.3 lib/appsignal/cli/helpers.rb
appsignal-4.1.2-java lib/appsignal/cli/helpers.rb
appsignal-4.1.2 lib/appsignal/cli/helpers.rb
appsignal-4.1.1-java lib/appsignal/cli/helpers.rb
appsignal-4.1.1 lib/appsignal/cli/helpers.rb
appsignal-4.1.0-java lib/appsignal/cli/helpers.rb
appsignal-4.1.0 lib/appsignal/cli/helpers.rb
appsignal-4.0.9-java lib/appsignal/cli/helpers.rb
appsignal-4.0.9 lib/appsignal/cli/helpers.rb
appsignal-4.0.8-java lib/appsignal/cli/helpers.rb
appsignal-4.0.8 lib/appsignal/cli/helpers.rb
appsignal-4.0.7-java lib/appsignal/cli/helpers.rb
appsignal-4.0.7 lib/appsignal/cli/helpers.rb
appsignal-4.0.6-java lib/appsignal/cli/helpers.rb
appsignal-4.0.6 lib/appsignal/cli/helpers.rb
appsignal-4.0.5-java lib/appsignal/cli/helpers.rb
appsignal-4.0.5 lib/appsignal/cli/helpers.rb