rubyx-debugger/lib/views/status_view.rb

48 lines
1.0 KiB
Ruby
Raw Normal View History

2015-08-20 20:03:00 +02:00
class StatusView < ElementView
2015-08-22 01:06:48 +02:00
def initialize interpreter
@interpreter = interpreter
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") <<
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") <<
div( "span.link" , link_text) <<
div( "br" , "Stdout") <<
div("span.stdout")
# set up event handler
@element.at_css(".act").on("click") { self.update }
2015-08-22 01:06:48 +02:00
return @element
end
2015-08-20 20:03:00 +02:00
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
@element.at_css(".link").text = link_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 link_text
"Link #{@interpreter.link}"
end
def state_text
"State #{@interpreter.state}"
end
def clock_text
2015-08-22 01:06:48 +02:00
"Instruction #{@interpreter.clock}"
end
end