lib/roku_builder/monitor.rb in roku_builder-3.12.2 vs lib/roku_builder/monitor.rb in roku_builder-3.12.4
- old
+ new
@@ -19,22 +19,23 @@
@show_prompt = false
end
# Monitor a development log on the Roku device
# @param type [Symbol] The log type to monitor
- def monitor(type:)
+ # @param regexp [Regexp] regular expression to filter text on
+ def monitor(type:, regexp: nil)
telnet_config = { 'Host' => @roku_ip_address, 'Port' => @ports[type] }
waitfor_config = { 'Match' => /./, 'Timeout' => false }
thread = Thread.new(telnet_config, waitfor_config) {|telnet,waitfor|
@logger.info "Monitoring #{type} console(#{telnet['Port']}) on #{telnet['Host'] }"
connection = Net::Telnet.new(telnet)
Thread.current[:connection] = connection
all_text = ""
while true
connection.waitfor(waitfor) do |txt|
- all_text = manage_text(all_text: all_text, txt: txt)
+ all_text = manage_text(all_text: all_text, txt: txt, regexp: regexp)
end
end
}
init_readline()
@@ -85,24 +86,28 @@
when "q"
thread.exit
running = false
else
thread[:connection].puts(command)
+ sleep(0.1)
end
rescue SystemExit, Interrupt
thread[:connection].puts("\C-c")
end
end
end
# Handle text from telnet
# @param all_text [String] remaining partial line text
# @param txt [String] current string from telnet
+ # @param regexp [Regexp] regular expression to filter text on
# @return [String] remaining partial line text
- def manage_text(all_text:, txt:)
+ def manage_text(all_text:, txt:, regexp: nil)
all_text += txt
while line = all_text.slice!(/^.*\n/) do
- puts line if !line.strip.empty?
+ if !line.strip.empty?
+ puts line if regexp.nil? or regexp.match(line)
+ end
end
if all_text.downcase == "BrightScript Debugger> ".downcase
@show_prompt = true
all_text = ""