Sha256: f24d31930bb0ea2790f86f59302c042ac15ed6dd52c8070a8083a1ff4e147d9b

Contents?: true

Size: 935 Bytes

Versions: 5

Compression:

Stored size: 935 Bytes

Contents

module WickedPdf
  class Progress
    require 'pty' # no support for windows
    require 'English'

    def initialize(callback = nil)
      @callback = callback
    end

    def execute(command)
      output = []
      begin
        PTY.spawn(command.join(' ')) do |stdout, _stdin, pid|
          begin
            stdout.sync
            stdout.each_line("\r") do |line|
              output << line.chomp
              @callback.call(line) if @callback
            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

5 entries across 5 versions & 1 rubygems

Version Path
adzap-wicked_pdf-2.0.0.beta5 lib/wicked_pdf/progress.rb
adzap-wicked_pdf-2.0.0.beta4 lib/wicked_pdf/progress.rb
adzap-wicked_pdf-2.0.0.beta3 lib/wicked_pdf/progress.rb
adzap-wicked_pdf-2.0.0.beta2 lib/wicked_pdf/progress.rb
adzap-wicked_pdf-2.0.0.beta1 lib/wicked_pdf/progress.rb