2015-08-24 01:45:33 +02:00
|
|
|
require "base/constant_view"
|
|
|
|
require "base/list_view"
|
2015-08-21 00:37:41 +02:00
|
|
|
|
2018-04-17 18:08:10 +02:00
|
|
|
class MomView < ListView
|
2015-08-21 00:37:41 +02:00
|
|
|
|
2015-08-24 01:45:33 +02:00
|
|
|
def initialize interpreter
|
|
|
|
@interpreter = interpreter
|
2018-04-17 18:08:10 +02:00
|
|
|
@current = nil
|
2015-10-21 13:05:18 +02:00
|
|
|
super([start_view])
|
2015-08-24 01:45:33 +02:00
|
|
|
@interpreter.register_event(:instruction_changed, self)
|
2015-10-21 13:05:18 +02:00
|
|
|
@interpreter.register_event(:state_changed, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_view
|
2018-04-17 18:20:31 +02:00
|
|
|
ConstantView.new( "span.mom_bright" , "starting" )
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
|
2015-08-24 01:45:33 +02:00
|
|
|
def instruction_changed
|
2018-04-17 18:08:10 +02:00
|
|
|
i = @interpreter.instruction
|
|
|
|
return unless i && i.source.is_a?(Mom::Instruction)
|
2018-04-17 19:25:56 +02:00
|
|
|
return if i.source == @current
|
|
|
|
@current = i.source
|
2018-04-17 18:08:10 +02:00
|
|
|
@element.at_css(".mom_bright").remove_class("mom_bright")
|
2018-04-17 19:25:56 +02:00
|
|
|
instruction = append_view( ConstantView.new( "span.mom_bright" , @current.to_s ) )
|
2018-04-17 18:08:10 +02:00
|
|
|
wrap_node_with( instruction , div )
|
2015-08-24 02:04:07 +02:00
|
|
|
remove_first if( @elements.length > 6)
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
2015-08-24 01:45:33 +02:00
|
|
|
|
|
|
|
def draw
|
|
|
|
super()
|
|
|
|
wrap_node_with @elements.first , div
|
2018-04-17 18:08:10 +02:00
|
|
|
wrap_element div(".mom_view") << div("h4" ,"Mom::Instruction")
|
2015-08-24 01:45:33 +02:00
|
|
|
@element
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|
|
|
|
|
2018-04-17 18:08:10 +02:00
|
|
|
def state_changed(old , new_s)
|
2015-10-21 13:05:18 +02:00
|
|
|
return unless new_s == :running
|
|
|
|
clear_view
|
2018-04-17 18:08:10 +02:00
|
|
|
@current = nil
|
2015-10-21 13:05:18 +02:00
|
|
|
append_view start_view
|
|
|
|
end
|
|
|
|
|
2015-08-21 00:37:41 +02:00
|
|
|
end
|