Sha256: 49711c487f087933a23e9d094e4ee5aa5bba0b754da6f6d511e6961745388a32

Contents?: true

Size: 1.15 KB

Versions: 18

Compression:

Stored size: 1.15 KB

Contents

module Mina
  class Runner
    class Pretty
      include Mina::Helpers::Output

      attr_reader :script, :coathooks

      def initialize(script)
        @script = Shellwords.shellsplit(script)
        @coathooks = 0
      end

      def run
        status =
          Open4.popen4(*script) do |pid, _stdin, stdout, stderr|
            # Handle `^C`.
            trap('INT') { handle_sigint(pid) }

            stdout_thread = Thread.new do
              while (line = stdout.gets)
                print_line(line)
              end
            end

            stderr_thread = Thread.new do
              while (line = stderr.gets)
                print_stderr(line)
              end
            end

            stdout_thread.join
            stderr_thread.join
          end

        status.exitstatus == 0
      end

      private

      def handle_sigint(pid)
        puts ''
        if coathooks > 1
          print_status 'Mina: SIGINT received again. Force quitting...'
          Process.kill 'KILL', pid
        else
          print_status 'Mina: SIGINT received.'
          Process.kill 'TERM', pid
        end
        @coathooks += 1
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mina-1.2.4 lib/mina/runner/pretty.rb
mina-1.2.3 lib/mina/runner/pretty.rb
mina-1.2.2 lib/mina/runner/pretty.rb
mina-1.2.1 lib/mina/runner/pretty.rb
mina-1.2.0 lib/mina/runner/pretty.rb
mina-1.1.1 lib/mina/runner/pretty.rb
mina-1.1.0 lib/mina/runner/pretty.rb
mina-1.0.7 lib/mina/runner/pretty.rb
mina-1.0.6 lib/mina/runner/pretty.rb
mina-1.0.5 lib/mina/runner/pretty.rb
mina-1.0.4 lib/mina/runner/pretty.rb
mina-1.0.3 lib/mina/runner/pretty.rb
mina-1.0.2 lib/mina/runner/pretty.rb
mina-1.0.0 lib/mina/runner/pretty.rb
mina-1.0.0.rc2 lib/mina/runner/pretty.rb
mina-1.0.0.beta5 lib/mina/runner/pretty.rb
mina-1.0.0.beta4 lib/mina/runner/pretty.rb
mina-1.0.0.beta3 lib/mina/runner/pretty.rb