rubyx-debugger/app/source_view.rb

39 lines
759 B
Ruby
Raw Normal View History

2015-07-22 15:22:54 +02:00
class SourceView
include React::Component
required_param :interpreter
2015-07-22 15:22:54 +02:00
2015-07-27 11:09:35 +02:00
define_state :sources => []
before_mount do
interpreter.register_event(:instruction_changed, self)
instruction_changed nil , interpreter.instruction
end
def instruction_changed old , ins
2015-07-28 15:16:09 +02:00
text = ins ? source_text(ins.source) : "exit"
2015-07-27 11:09:35 +02:00
return if sources.last == text
sources << text
sources.shift if sources.length > 5
sources! sources
2015-07-27 11:09:35 +02:00
end
2015-07-22 15:22:54 +02:00
def render
div.source_view do
h4 {"Virtual Machine Instruction"}
2015-07-27 11:09:35 +02:00
sources.each do |s|
s.br
end
2015-07-22 15:22:54 +02:00
end
end
def source_text source
2015-07-27 11:09:35 +02:00
if source.is_a? Virtual::Instruction
return source.class.name
else
return "Method: #{source.name}"
end
end
2015-07-22 15:22:54 +02:00
end