Permalink
Browse files

Merge branch 'master' of git://github.com/glejeune/brirb

Conflicts:
brirb.rb
  • Loading branch information...
2 parents 5691cfa + 12d8de8 commit 217bcaa4cb665e6c71dd038ae2fc9183b068bd9d @rkh committed Jul 20, 2010
Showing with 13 additions and 5 deletions.
  1. +3 −2 brirb.coffee
  2. +10 −3 brirb.rb
View
@@ -1,7 +1,8 @@
$(document).ready ->
input: $("#input")
output: (str) ->
- $("#log").append "$str<br>"
+ if str.length > 0
+ $("#log").append str+"<br>"
input.attr {scrollTop: input.attr("scrollHeight") }
ws: new WebSocket("ws://127.0.0.1:8080")
@@ -14,7 +15,7 @@ $(document).ready ->
$("form").submit ->
value: input.val()
ws.send value
- output "&gt;&gt; $value"
+ output "&gt;&gt; "+value
input.val ""
input.focus()
false
View
@@ -7,18 +7,25 @@
EventMachine::WebSocket.start(:host => '127.0.0.1', :port => 8080) do |ws|
brirb_binding = binding
line = 1
+ cmd = ""
_ = nil
- ws.onopen { ws.send RUBY_DESCRIPTION }
+ ws.onopen { ws.send RUBY_DESCRIPTION }
ws.onmessage do |msg|
+ cmd << msg << "\n"
response = ""
begin
stdout = capture_stdout do
- _ = eval(msg, brirb_binding, '(brirb session)', line)
+ _ = eval(cmd, brirb_binding, '(brirb session)', line)
end
line += 1
response << stdout << "=> #{_.inspect}"
+ cmd = ""
rescue Exception => e
- response << e.to_s << "\n" << e.backtrace.map { |l| "\t#{l}" }.join("\n")
+ unless e.class == SyntaxError
+ response << e.to_s << " (" << e.class.to_s << ") \n" << e.backtrace.map { |l| "\t#{l}" }.join("\n")
+ else
+ response = ""
+ end
end
ws.send EscapeUtils.escape_html(response).gsub("\n", "<br>").gsub("\t", " ").gsub(" ", "&nbsp;")
end

0 comments on commit 217bcaa

Please sign in to comment.