Sha256: 80c686715f89804ac7770e79387e799f094dee8516e1d91bacc83a4c7e46f8af

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

class Shoes
  module Logger
    class << self

      def register(name, obj)
        @loggers ||= { }
        @loggers[name] = obj
      end

      def unregister(name)
        @loggers.delete(name)
      end

      def get(name)
        @loggers && @loggers[name]
      end
    end

    def self.setup
      Shoes.app do
        def update
          if @hash != Shoes::LOG.hash
            @hash = Shoes::LOG.hash
            @log.clear do
              Shoes::LOG.each_with_index do |(typ, msg), index|
                stack do
                  background "#f1f5e1" if index % 2 == 0
                  background rgb(220, 220, 220) if index % 2 != 0
                  para typ, :stroke => blue
                  flow do
                    stack :margin => 4 do
                      s = msg.to_s
                      para s, :margin => 4, :margin_top => 0
                    end
                  end
                end
              end
            end
          end
        end

        stack do
          flow do
            background black
            stack do
              tagline "Shoes Console", stroke: white
            end
            button "Clear", margin: 6, width: 80, height: 40, right: 10 do
              Shoes::LOG.clear
            end
          end
          @log, @hash = stack, nil
          update

          every(0.2) do
            update
          end
        end
      end
    end
  end
end

Dir[File.join(File.dirname(__FILE__), "logger", "*.rb")].each { |logger|
  require logger
}

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
shoes-dsl-4.0.0.pre2 lib/shoes/logger.rb
shoes-4.0.0.pre1 lib/shoes/logger.rb