rubyx-debugger/lib/views/instruction_view.rb
Torsten Ruger 94292bf1ca allow for empty view
and reset view when interpreter restarts
2015-10-21 14:05:18 +03:00

42 lines
1019 B
Ruby

require "base/constant_view"
require "base/list_view"
class InstructionView < ListView
def initialize interpreter
@interpreter = interpreter
super([start_view])
@interpreter.register_event(:instruction_changed, self)
@interpreter.register_event(:state_changed, self)
end
def start_view
ConstantView.new( "span.bright" , "starting" )
end
def instruction_changed
@element.at_css(".bright").remove_class("bright")
instruction = append_view( ConstantView.new( "span.bright" , instruction_text ) )
wrap_node_with instruction , div
remove_first if( @elements.length > 6)
end
def draw
super()
wrap_node_with @elements.first , div
wrap_element div(".source_view") << div("h4" ,"Virtual Machine Instruction")
@element
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
@interpreter.instruction.to_s
end
end