Sha256: c0041b6920f4c10efe75bdbcd668dd43cdb05a9ea547eac6be33f40b5c33ef51

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'colorize'
require 'io/console'

module EacRubyUtils
  module Console
    # https://github.com/fazibear/colorize
    module Speaker
      def puts(string = '')
        STDERR.puts(string.to_s)
      end

      def out(string = '')
        STDOUT.write(string.to_s)
      end

      def fatal_error(string)
        puts "ERROR: #{string}".white.on_red
        Kernel.exit 1
      end

      def title(string)
        string = string.to_s
        puts(('-' * (8 + string.length)).green)
        puts("--- #{string} ---".green)
        puts(('-' * (8 + string.length)).green)
        puts
      end

      def info(string)
        puts string.to_s.white
      end

      def infom(string)
        puts string.to_s.light_yellow
      end

      def warn(string)
        puts string.to_s.yellow
      end

      def request_input(question, options = {})
        STDERR.write "#{question}: ".to_s.yellow
        if options[:noecho]
          r = STDIN.noecho(&:gets).chomp.strip
          STDERR.write("\n")
          r
        else
          STDIN.gets.chomp.strip
        end
      end

      def infov(*args)
        r = []
        args.each_with_index do |v, i|
          if i.even?
            r << "#{v}: ".cyan
          else
            r.last << v.to_s
          end
        end
        puts r.join(', ')
      end

      def success(string)
        puts string.to_s.green
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eac_ruby_utils-0.10.1 lib/eac_ruby_utils/console/speaker.rb