class ProgressMonitor::Display::InputLoop
Attributes
queue[R]
Public Class Methods
new(queue)
click to toggle source
# File lib/progress_monitor/display/input_loop.rb, line 6 def initialize(queue) @queue = queue @status = :normal end
Public Instance Methods
perform()
click to toggle source
# File lib/progress_monitor/display/input_loop.rb, line 11 def perform loop { get_key } end
Private Instance Methods
get_key()
click to toggle source
# File lib/progress_monitor/display/input_loop.rb, line 17 def get_key key = STDIN.getch case @status when :normal if key == "\e" @status = :escape else send_key(key) end when :escape if key == "[" @status = :special else send_key("\e#{key}") @status = :normal end when :special send_key("\e[#{key}") @status = :normal end rescue => e puts e.inspect end
send_key(key)
click to toggle source
# File lib/progress_monitor/display/input_loop.rb, line 41 def send_key(key) @queue << { type: :input, key: key } end