Sha256: 03a8f77495910e20480bc4202defc85f90e0b5ba463078a4c38a42f54db9f257

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Mutant
  class Reporter
    class CLI
      # Interface to the optionally present tput binary
      class Tput
        include Adamantium, Concord::Public.new(:prepare, :restore)

        private_class_method :new

        # Detected tput support
        #
        # @return [Tput]
        #   if tput support is present
        #
        # @return [nil]
        #   otherwise
        def self.detect
          reset   = capture('tput reset')
          save    = capture('tput sc') if reset
          restore = capture('tput rc') if save
          clean   = capture('tput ed') || capture('tput cd') if restore
          new(reset + save, restore + clean) if clean
        end

        # Capture output
        #
        # @param [String] command
        #   command to run
        #
        # @return [String]
        #   stdout of command on success
        #
        # @return [nil]
        #   otherwise
        def self.capture(command)
          stdout, _stderr, exitstatus = Open3.capture3(command)
          stdout if exitstatus.success?
        end
        private_class_method :capture

      end # Tput
    end # CLI
  end # Reporter
end # Mutant

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.8.24 lib/mutant/reporter/cli/tput.rb
mutant-0.8.23 lib/mutant/reporter/cli/tput.rb
mutant-0.8.22 lib/mutant/reporter/cli/tput.rb
mutant-0.8.21 lib/mutant/reporter/cli/tput.rb
mutant-0.8.20 lib/mutant/reporter/cli/tput.rb
mutant-0.8.19 lib/mutant/reporter/cli/tput.rb
mutant-0.8.18 lib/mutant/reporter/cli/tput.rb
mutant-0.8.17 lib/mutant/reporter/cli/tput.rb