class Roku::Input
Constants
- BINDINGS
Public Instance Methods
run()
click to toggle source
# File lib/roku/input.rb, line 17 def run while (input = read_char) case input when 'a' launch_app(prompt('Launch: ')) when 'q', "\u0003", "\e" break when *BINDINGS.keys Roku::Client.keypress(BINDINGS[input]) else puts input.inspect end end end
Private Instance Methods
launch_app(query)
click to toggle source
# File lib/roku/input.rb, line 50 def launch_app(query) app = Roku::Client.apps.find { |a| a.name.casecmp(query).zero? } if app.nil? print "\rNo app found." else print "\rLaunching #{app.name}." app.launch! end end
prompt(label)
click to toggle source
# File lib/roku/input.rb, line 45 def prompt(label) print label $stdin.gets.chomp end
read_char()
click to toggle source
# File lib/roku/input.rb, line 34 def read_char $stdin.raw do |stdin| input = stdin.getc.chr if input == "\e" input << stdin.read_nonblock(3) rescue nil input << stdin.read_nonblock(2) rescue nil end return input end end