rubyx-debugger/lib/views/mom_view.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

require "base/constant_view"
require "base/list_view"
2015-08-21 00:37:41 +02:00
class MomView < ListView
2015-08-21 00:37:41 +02:00
def initialize interpreter
@interpreter = interpreter
@current = nil
super([start_view])
@interpreter.register_event(:instruction_changed, self)
@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
def instruction_changed
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
@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 ) )
wrap_node_with( instruction , div )
remove_first if( @elements.length > 6)
2015-08-21 00:37:41 +02:00
end
def draw
super()
wrap_node_with @elements.first , div
wrap_element div(".mom_view") << div("h4" ,"Mom::Instruction")
@element
2015-08-21 00:37:41 +02:00
end
def state_changed(old , new_s)
return unless new_s == :running
clear_view
@current = nil
append_view start_view
end
2015-08-21 00:37:41 +02:00
end