lib/roku_builder/monitor.rb in roku_builder-3.11.0 vs lib/roku_builder/monitor.rb in roku_builder-3.11.1
- old
+ new
@@ -20,18 +20,12 @@
end
# Monitor a development log on the Roku device
# @param type [Symbol] The log type to monitor
def monitor(type:)
- telnet_config = {
- 'Host' => @roku_ip_address,
- 'Port' => @ports[type]
- }
- waitfor_config = {
- 'Match' => /./,
- 'Timeout' => false
- }
+ 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
@@ -40,12 +34,20 @@
connection.waitfor(waitfor) do |txt|
all_text = manage_text(all_text: all_text, txt: txt)
end
end
}
- # setup readline
+ init_readline()
+
+ run_prompt(thread: thread)
+ end
+
+ private
+
+ # Setup tab completeion for Readline
+ def init_readline
libedit = false
begin
Readline.vi_editing_mode
rescue NotImplementedError
libedit = true
@@ -60,12 +62,14 @@
comp = proc { |s| commands.grep( /^#{Regexp.escape(s)}/ ) }
Readline.completion_append_character = " "
Readline.completion_proc = comp
+ end
-
+ # Check if needs to display prompt, displays prompt, and processes input
+ def run_prompt(thread:)
running = true
@logger.unknown "Q to exit"
while running
begin
if @show_prompt
@@ -88,12 +92,10 @@
thread[:connection].puts("\C-c")
end
end
end
- private
-
- # Handel text from telnet
+ # Handle text from telnet
# @param all_text [String] remaining partial line text
# @param txt [String] current string from telnet
# @return [String] remaining partial line text
def manage_text(all_text:, txt:)
all_text += txt