Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Make style more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Jan 7, 2011
1 parent 480876e commit 5a84693
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 43 deletions.
54 changes: 25 additions & 29 deletions lib/net/ssh/shell/process.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Net; module SSH; class Shell

class Process
attr_reader :state
attr_reader :command
Expand Down Expand Up @@ -86,39 +85,36 @@ def on_finish(&callback)
@on_finish = callback
end

private
protected

def output!(data)
return unless @on_output
@on_output.call(self, data)
end
def output!(data)
@on_output.call(self, data) if @on_output
end

def on_stdout(ch, data)
if data.strip =~ /^#{manager.separator} (\d+)$/
before = $`
output!(before) unless before.empty?
finished!($1)
else
output!(data)
end
def on_stdout(ch, data)
if data.strip =~ /^#{manager.separator} (\d+)$/
before = $`
output!(before) unless before.empty?
finished!($1)
else
output!(data)
end
end

def on_stderr(ch, type, data)
return unless @on_error_output
@on_error_output.call(self, data)
end
def on_stderr(ch, type, data)
@on_error_output.call(self, data) if @on_error_output
end

def on_close(ch)
manager.on_channel_close(ch)
finished!(-1)
end
def on_close(ch)
manager.on_channel_close(ch)
finished!(-1)
end

def finished!(status)
@state = :finished
@exit_status = status.to_i
@on_finish.call(self) if @on_finish
manager.child_finished(self)
end
def finished!(status)
@state = :finished
@exit_status = status.to_i
@on_finish.call(self) if @on_finish
manager.child_finished(self)
end
end

end; end; end
26 changes: 12 additions & 14 deletions lib/net/ssh/shell/subshell.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
require 'net/ssh/shell/process'

module Net; module SSH; class Shell

class Subshell < Process
private
protected

def on_stdout(ch, data)
if !output!(data)
ch.on_data(&method(:look_for_finalize_initializer))
ch.send_data("export PS1=; echo #{manager.separator} $?\n")
end
def on_stdout(ch, data)
if !output!(data)
ch.on_data(&method(:look_for_finalize_initializer))
ch.send_data("export PS1=; echo #{manager.separator} $?\n")
end
end

def look_for_finalize_initializer(ch, data)
if data =~ /#{manager.separator} (\d+)/
ch.on_close(&@master_onclose)
finished!($1)
end
def look_for_finalize_initializer(ch, data)
if data =~ /#{manager.separator} (\d+)/
ch.on_close(&@master_onclose)
finished!($1)
end
end
end

end; end; end
end; end; end

0 comments on commit 5a84693

Please sign in to comment.