Sha256: 865d3f4a6f11a802a1ab264d8fcf0c4875c1c4893823eaabc94d1311d2d02d40

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

class WickedPdf
  module Progress
    require 'pty' if RbConfig::CONFIG['target_os'] !~ /mswin|mingw/ # no support for windows
    require 'English'

    def track_progress?(options)
      options[:progress] && !on_windows?
    end

    def invoke_with_progress(command, options)
      output = []
      begin
        PTY.spawn(command.join(' ')) do |stdout, _stdin, pid|
          begin
            stdout.sync
            stdout.each_line("\r") do |line|
              output << line.chomp
              options[:progress].call(line) if options[:progress]
            end
          rescue Errno::EIO # rubocop:disable Lint/HandleExceptions
            # child process is terminated, this is expected behaviour
          ensure
            ::Process.wait pid
          end
        end
      rescue PTY::ChildExited
        puts 'The child process exited!'
      end
      err = output.join('\n')
      raise "#{command} failed (exitstatus 0). Output was: #{err}" unless $CHILD_STATUS && $CHILD_STATUS.exitstatus.zero?
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wicked_pdf-2.7.0 lib/wicked_pdf/progress.rb
wicked_pdf-2.6.3 lib/wicked_pdf/progress.rb
wicked_pdf-2.6.2 lib/wicked_pdf/progress.rb
wicked_pdf-2.6.0 lib/wicked_pdf/progress.rb
wicked_pdf-2.1.0 lib/wicked_pdf/progress.rb
wicked_pdf-2.0.2 lib/wicked_pdf/progress.rb
wicked_pdf-2.0.1 lib/wicked_pdf/progress.rb
wicked_pdf-2.0.0 lib/wicked_pdf/progress.rb
wicked_pdf-1.4.0 lib/wicked_pdf/progress.rb
wicked_pdf-1.3.0 lib/wicked_pdf/progress.rb
wicked_pdf-1.2.2 lib/wicked_pdf/progress.rb