Class: Mina::Runner::Pretty

Inherits:
Object
  • Object
show all
Includes:
Helpers::Output
Defined in:
lib/mina/runner/pretty.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Output

#color, #print_command, #print_error, #print_info, #print_line, #print_status, #print_stderr, #print_stdout

Constructor Details

#initialize(script) ⇒ Pretty

Returns a new instance of Pretty


8
9
10
11
# File 'lib/mina/runner/pretty.rb', line 8

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

Instance Attribute Details

#coathooksObject (readonly)

Returns the value of attribute coathooks


6
7
8
# File 'lib/mina/runner/pretty.rb', line 6

def coathooks
  @coathooks
end

#scriptObject (readonly)

Returns the value of attribute script


6
7
8
# File 'lib/mina/runner/pretty.rb', line 6

def script
  @script
end

Instance Method Details

#runObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mina/runner/pretty.rb', line 13

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