Sha256: adc93eafc4afa661281677c744db5f0247847544fb90dcb5bb1722ee46d29d90

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module Gitscrub
  module UI

    @@out_stream
    @@in_stream

    class << self
      
      def out_stream=(out)
        @@out_stream = out
      end

      def in_stream=(in_stream)
        @@in_stream = in_stream
      end

      def puts(string = "")
        @@out_stream.puts(string)
      end

      def print(string)
        @@out_stream.print(string)
      end

      def gets
        @@in_stream.gets
      end

      def line
        puts("*"*80)
      end

      def word_box(string)
        space_length = (80/2) - ((string.length/2)+1)
        line
        print "*"
        print " "*space_length
        print string
        print " "*space_length
        puts "*"
        line
      end

      def request(msg)
        print("#{msg} ")
        gets.chomp
      end
      
      def ask(msg)
        request("#{msg} [yn] ") == 'y'
      end

      def colorize(text, color_code)
        puts "#{color_code}#{text}\033[0m"
      end

      def error(text)
        colorize(text, "\033[31m")
      end

      def success(text)
        colorize(text, "\033[32m")
      end

    end

    def method_missing(method, *args, &block)
      return UI.send(method, *args) if UI.methods(false).include?(method)
      super
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gitscrub-0.0.8 lib/gitscrub/ui.rb
gitscrub-0.0.7 lib/gitscrub/ui.rb
gitscrub-0.0.6 lib/gitscrub/ui.rb