rubyx-debugger/lib/views/status_view.rb

73 lines
1.6 KiB
Ruby
Raw Normal View History

require "browser/delay"
2015-08-20 20:03:00 +02:00
class StatusView < ElementView
2015-08-22 01:06:48 +02:00
def initialize interpreter
@interpreter = interpreter
@running = false
2015-08-22 01:06:48 +02:00
end
2015-08-20 20:03:00 +02:00
2015-08-22 01:06:48 +02:00
def draw
@element = div(".status_view") <<
2015-08-24 01:44:50 +02:00
div("h4" , "Interpreter" ) <<
2015-08-22 01:06:48 +02:00
div("button.act" , "Next") <<
2015-11-01 17:11:00 +01:00
div("button.crawl" , "Crawl") <<
div("button.run" , "Run") <<
2015-11-01 17:11:00 +01:00
div("button.wizz" , "Wizz") <<
2015-08-22 01:06:48 +02:00
div( "br") <<
2015-08-24 01:44:50 +02:00
div("span.clock" , clock_text) <<
div( "br") <<
2015-08-22 01:06:48 +02:00
div("span.state" , state_text) <<
div( "br" , "Stdout") <<
div("span.stdout")
# set up event handler
@element.at_css(".act").on("click") { self.update }
2015-11-01 17:11:00 +01:00
@element.at_css(".crawl").on("mousedown") { self.start( 0.5 ) }
@element.at_css(".run").on("mousedown") { self.start( 0.1 ) }
@element.at_css(".wizz").on("mousedown") { self.start( 0.05 ) }
@element.at_css(".crawl").on("mouseup") { self.stop }
@element.at_css(".run").on("mouseup") { self.stop }
2015-11-01 17:11:00 +01:00
@element.at_css(".wizz").on("mouseup") { self.stop }
2015-08-22 01:06:48 +02:00
return @element
end
2015-08-20 20:03:00 +02:00
2015-11-01 17:11:00 +01:00
def start(speed)
@running = speed
run
end
def stop
@running = false
end
def run
return unless @running
begin
proc = Proc.new do
self.update
self.run
end
2015-11-01 17:11:00 +01:00
proc.after( @running )
rescue => e
puts e
end
end
2015-08-22 01:06:48 +02:00
def update
begin
@interpreter.tick
rescue => e
puts e
end
@element.at_css(".clock").text = clock_text
2015-10-22 13:44:12 +02:00
@element.at_css(".state").text = state_text
@element.at_css(".stdout").text = @interpreter.stdout
2015-08-22 01:06:48 +02:00
end
def state_text
"State #{@interpreter.state}"
end
def clock_text
2015-08-22 01:06:48 +02:00
"Instruction #{@interpreter.clock}"
end
end