Skip to content

Commit

Permalink
readline support for pry-debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
mchaisse committed Jul 21, 2016
1 parent 5f5502e commit fb22de1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
12 changes: 10 additions & 2 deletions lib/foreman/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,16 @@ def handle_io(readers)
if reader.eof?
@readers.delete_if { |key, value| value == reader }
else
data = reader.gets
output_with_mutex name_for(@readers.invert[reader]), data
$stdout.print marker(name_for(@readers.invert[reader]))

loop do
ch = reader.getc

$stdout.print ch
$stdout.flush

break if ch == "\n"
end
end
end
end
Expand Down
15 changes: 8 additions & 7 deletions lib/foreman/engine/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ def startup

def output(name, data)
data.to_s.lines.map(&:chomp).each do |message|
output = ""
output += $stdout.color(@colors[name.split(".").first].to_sym)
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
output += $stdout.color(:reset)
output += message
$stdout.puts output
$stdout.flush
$stdout.puts(marker(name) + message)
end
rescue Errno::EPIPE
terminate_gracefully
end

def marker(name)
output = ""
output += $stdout.color(@colors[name.split(".").first].to_sym)
output += "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | "
output += $stdout.color(:reset)
end

def shutdown
end

Expand Down
17 changes: 17 additions & 0 deletions spec/foreman/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@
end

describe "with a valid Procfile" do
describe "Readline applications" do
it "outputs prompt" do
without_fakefs do
output = foreman("start irb -f #{resource_path("Procfile.IRB")}")
expect(output).to match(/irb\(main\):001:0>/)
end
end

it "outputs prompt and responds to input" do
without_fakefs do
output = foreman("start irbinput -f #{resource_path("Procfile.IRB")}")
expect(output).to match(/# leet foreman/)
expect(output).to match(/=> 74331/)
end
end
end

it "can run a single command" do
without_fakefs do
output = foreman("start env -f #{resource_path("Procfile")}")
Expand Down
2 changes: 2 additions & 0 deletions spec/resources/Procfile.IRB
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
irb: bin/irb
irbinput: bin/irbinput
5 changes: 5 additions & 0 deletions spec/resources/bin/irb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby
require 'irb'
Thread.new { IRB.start }
sleep 1
abort
16 changes: 16 additions & 0 deletions spec/resources/bin/irbinput
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby
require 'pty'
require 'irb'

PTY.spawn('irb') do |reader, writer|
Thread.new do
sleep 1
writer.puts '0xf013 + 0x3248 # leet foreman'
end

loop do
sleep 2
print reader.sysread(256)
abort
end
end

0 comments on commit fb22de1

Please sign in to comment.