Class: Byebug::DAP::CapturedIO Private
- Inherits:
-
Object
- Object
- Byebug::DAP::CapturedIO
- Defined in:
- lib/byebug/dap/helpers/captured_io.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Captures STDOUT and STDERR. See CapturedOutput.
Instance Method Summary collapse
-
#capture ⇒ Object
private
In a loop, read from the captured STDOUT and STDERR and send an output event to the active session’s client (if there is an active session), and optionally forward the output to the original STDOUT/STDERR.
-
#initialize(forward_stdout, forward_stderr) ⇒ CapturedIO
constructor
private
Capture STDOUT and STDERR and create a new gem:byebug:Byebuggem:byebug:Byebug::DebugThread running #capture.
-
#log ⇒ std:IO
private
Return an IO that can be used for logging.
-
#restore ⇒ Object
private
Restore the original STDOUT and STDERR.
Constructor Details
#initialize(forward_stdout, forward_stderr) ⇒ CapturedIO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Capture STDOUT and STDERR and create a new Byebug::DAP::CapturedIO.gem:byebug:Byebuggem:byebug:Byebug::DebugThread running #capture. See Byebug::DAP::CapturedOutput#initialize.
10 11 12 13 14 15 16 17 18 |
# File 'lib/byebug/dap/helpers/captured_io.rb', line 10 def initialize(forward_stdout, forward_stderr) @forward_stdout = forward_stdout @forward_stderr = forward_stderr @stdout = CapturedOutput.new STDOUT @stderr = CapturedOutput.new STDERR @stop = false Byebug::DebugThread.new { capture } end |
Instance Method Details
#capture ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
In a loop, read from the captured STDOUT and STDERR and send an output event to the active session’s client (if there is an active session), and optionally forward the output to the original STDOUT/STDERR.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/byebug/dap/helpers/captured_io.rb', line 46 def capture until @stop do r, = IO.select([@stdout.captured, @stderr.captured]) r.each do |r| case r when @stdout.captured b = @stdout.captured.read_nonblock(1024) @stdout.original.write(b) if @forward_stdout send(:stdout, b) when @stderr.captured b = @stderr.captured.read_nonblock(1024) @stderr.original.write(b) if @forward_stderr send(:stderr, b) end end end rescue EOFError, Errno::EBADF rescue StandardError => e log.puts "#{e.} (#{e.class})", *e.backtrace end |
#log ⇒ std:IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return an IO that can be used for logging.
22 23 24 25 26 27 28 29 30 |
# File 'lib/byebug/dap/helpers/captured_io.rb', line 22 def log if defined?(LOG) LOG elsif @stderr @stderr.original else STDERR end end |
#restore ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Restore the original STDOUT and STDERR.
33 34 35 36 37 |
# File 'lib/byebug/dap/helpers/captured_io.rb', line 33 def restore @stop = true @stdout.restore @stderr.restore end |