2015-10-29 17:36:42 +01:00
|
|
|
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
|
2015-10-29 17:36:42 +01:00
|
|
|
@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
|
2015-08-22 01:37:15 +02:00
|
|
|
@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") <<
|
2015-10-29 17:36:42 +01:00
|
|
|
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
|
2015-08-22 01:59:29 +02:00
|
|
|
@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 }
|
2015-10-29 17:36:42 +01:00
|
|
|
@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-10-29 17:36:42 +01:00
|
|
|
|
2015-11-01 17:11:00 +01:00
|
|
|
def start(speed)
|
|
|
|
@running = speed
|
2015-10-29 17:36:42 +01:00
|
|
|
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 )
|
2015-10-29 17:36:42 +01:00
|
|
|
rescue => e
|
|
|
|
puts e
|
|
|
|
end
|
|
|
|
end
|
2015-08-22 01:06:48 +02:00
|
|
|
def update
|
2015-10-22 16:09:05 +02:00
|
|
|
begin
|
|
|
|
@interpreter.tick
|
|
|
|
rescue => e
|
|
|
|
puts e
|
|
|
|
end
|
2015-08-22 01:59:29 +02:00
|
|
|
@element.at_css(".clock").text = clock_text
|
2015-10-22 13:44:12 +02:00
|
|
|
@element.at_css(".state").text = state_text
|
2015-08-22 01:59:29 +02:00
|
|
|
@element.at_css(".stdout").text = @interpreter.stdout
|
2015-08-22 01:06:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def state_text
|
|
|
|
"State #{@interpreter.state}"
|
|
|
|
end
|
|
|
|
|
2015-08-22 01:59:29 +02:00
|
|
|
def clock_text
|
2015-08-22 01:06:48 +02:00
|
|
|
"Instruction #{@interpreter.clock}"
|
|
|
|
end
|
|
|
|
end
|