Module: Mina::ExecHelpers::Sys

Extended by:
Sys
Included in:
Sys
Defined in:
lib/mina/exec_helpers.rb

Overview

## Private methods Delegate functions, mostly.

Instance Method Summary collapse

Instance Method Details

#handle_sigint(count, pid, this) ⇒ Object

### Sys.handle_sigint! Called when a ‘^C` is pressed. The param `count` is how many times it’s been pressed since. Returns nothing.



49
50
51
52
53
54
55
56
57
58
# File 'lib/mina/exec_helpers.rb', line 49

def handle_sigint(count, pid, this)
  puts ""
  if count > 1
    this.print_status "Mina: SIGINT received again. Force quitting..."
    Process.kill "KILL", pid
  else
    this.print_status "Mina: SIGINT received."
    Process.kill "TERM", pid
  end
end

#stream_stderr!(err, &blk) ⇒ Object

### Sys.stream_stderr! Internal: Read from stderr stream ‘err` [0], supress expected errors [1], and yield. Returns the thread.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mina/exec_helpers.rb', line 64

def stream_stderr!(err, &blk)
  Thread.new do
    begin
      while str = err.gets #[0]
        next if str.include? "bash: no job control in this shell" #[1]
        next if str.include? "stdin is not a terminal"

        yield str.strip #[2]
      end
    rescue Interrupt
    end
  end
end

#stream_stdin!(&blk) ⇒ Object

### Sys.stream_stdin! Internal: Read from the real stdin stream and pass it onto the given stdin stream ‘i`. Returns the thread.



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mina/exec_helpers.rb', line 82

def stream_stdin!(&blk)
  Thread.new do
    begin
      while (char = STDIN.getbyte rescue nil)
        yield char if char
      end
    rescue Interrupt
    # rubinius 
    rescue SignalException
    end
  end
end

#stream_stdout(o, &blk) ⇒ Object

### Sys.stream_stdout Internal: Read from given stdout stream ‘o` and delegate it to the output helper.



99
100
101
102
103
104
105
106
# File 'lib/mina/exec_helpers.rb', line 99

def stream_stdout(o, &blk)
  while str = o.getc
    # Ruby 1.8.7 fix
    str = str.chr if str.is_a? Fixnum
    
    yield str
  end
end