Sha256: 5bb24caf700c83779b0f1048cd1b218a4a955d2253d709014cd5ee9d553107f2

Contents?: true

Size: 1.93 KB

Versions: 59

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

module Mutant
  class Reporter
    class CLI
      # CLI output format
      #
      # rubocop:disable Style/FormatString
      class Format
        include AbstractType, Concord.new(:tty)

        # Start representation
        #
        # @param [Env] env
        #
        # @return [String]
        abstract_method :start

        # Progress representation
        #
        # @param [Runner::Status] status
        #
        # @return [String]
        abstract_method :progress

        # Report delay in seconds
        #
        # @return [Float]
        def delay
          self.class::REPORT_DELAY
        end

        # Output abstraction to decouple tty? from buffer
        class Output
          include Concord.new(:tty, :buffer)

          # Test if output is a tty
          #
          # @return [Boolean]
          alias_method :tty?, :tty
          public :tty?

          %i[puts write].each do |name|
            define_method(name) do |*args, &block|
              buffer.public_send(name, *args, &block)
            end
          end
        end # Output

      private

        def format(printer, object)
          buffer = new_buffer
          printer.call(Output.new(tty, buffer), object)
          buffer.rewind
          buffer.read
        end

        # Format for progressive non rewindable output
        class Progressive < self

          REPORT_FREQUENCY = 1.0
          REPORT_DELAY     = 1 / REPORT_FREQUENCY

          # Start representation
          #
          # @return [String]
          def start(env)
            format(Printer::Env, env)
          end

          # Progress representation
          #
          # @return [String]
          def progress(status)
            format(Printer::StatusProgressive, status)
          end

        private

          def new_buffer
            StringIO.new
          end

        end # Progressive
      end # Format
    end # CLI
  end # Reporter
end # Mutant

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
mutant-0.11.18 lib/mutant/reporter/cli/format.rb
mutant-0.11.17 lib/mutant/reporter/cli/format.rb
mutant-0.11.16 lib/mutant/reporter/cli/format.rb
mutant-0.11.15 lib/mutant/reporter/cli/format.rb
mutant-0.11.14 lib/mutant/reporter/cli/format.rb
mutant-0.11.13 lib/mutant/reporter/cli/format.rb
mutant-0.11.12 lib/mutant/reporter/cli/format.rb
mutant-0.11.11 lib/mutant/reporter/cli/format.rb
mutant-0.11.10 lib/mutant/reporter/cli/format.rb
mutant-0.11.9 lib/mutant/reporter/cli/format.rb
mutant-0.11.8 lib/mutant/reporter/cli/format.rb
mutant-0.11.7 lib/mutant/reporter/cli/format.rb
mutant-0.11.6 lib/mutant/reporter/cli/format.rb
mutant-0.11.5 lib/mutant/reporter/cli/format.rb
mutant-0.11.4 lib/mutant/reporter/cli/format.rb
mutant-0.11.3 lib/mutant/reporter/cli/format.rb
mutant-0.11.2 lib/mutant/reporter/cli/format.rb
mutant-0.11.1 lib/mutant/reporter/cli/format.rb
mutant-0.11.0 lib/mutant/reporter/cli/format.rb
mutant-0.10.35 lib/mutant/reporter/cli/format.rb