Class: Wokku::PtySession

Inherits:
Object
  • Object
show all
Defined in:
lib/wokku/pty_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cable:, tty:) ⇒ PtySession

Returns a new instance of PtySession.



10
11
12
13
14
15
# File 'lib/wokku/pty_session.rb', line 10

def initialize(cable:, tty:)
  @cable = cable
  @tty = tty
  @exit_code = nil
  @done = false
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



8
9
10
# File 'lib/wokku/pty_session.rb', line 8

def exit_code
  @exit_code
end

Instance Method Details

#runObject

Runs until @done is set by an “exit” or “error” message. Optional block (used in specs) is called once per pump tick and may return :stop.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wokku/pty_session.rb', line 24

def run
  install_message_handler
  install_signal_handlers if @tty

  IO.console.raw! if @tty
  begin
    loop do
      break if @done
      forward_stdin if @tty
      @cable.pump(0.05)
      break if block_given? && yield == :stop
    end
  ensure
    IO.console.cooked! if @tty
  end
end

#start!(mode:, target:, argv: []) ⇒ Object



17
18
19
20
# File 'lib/wokku/pty_session.rb', line 17

def start!(mode:, target:, argv: [])
  rows, cols = current_winsize
  @cable.send_message(type: "start", mode: mode, target: target, argv: argv, cols: cols, rows: rows)
end