rubyx-debugger/lib/views/risc_view.rb

44 lines
1.0 KiB
Ruby
Raw Normal View History

require "base/constant_view"
require "base/list_view"
2015-08-21 00:37:41 +02:00
class RiscView < ListView
2015-08-21 00:37:41 +02:00
def initialize interpreter
@interpreter = interpreter
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.risc_bright" , "starting" )
2015-08-21 00:37:41 +02:00
end
def instruction_changed
2018-04-17 18:20:31 +02:00
@element.at_css(".risc_bright").remove_class("risc_bright")
instruction = append_view( ConstantView.new( "span.risc_bright" , instruction_text ) )
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(".risc_view") << div("h4" ,"Register Machine Instruction")
@element
2015-08-21 00:37:41 +02:00
end
def state_changed old , new_s
return unless new_s == :running
clear_view
append_view start_view
end
def instruction_text
return "" unless @interpreter.instruction
2018-04-06 12:03:39 +02:00
text = @interpreter.instruction.to_s
text.split("(").first
2015-08-21 00:37:41 +02:00
end
2015-10-29 15:49:14 +01:00
2015-08-21 00:37:41 +02:00
end