Method: Textbringer::Controller#read_event

Defined in:
lib/textbringer/controller.rb

#read_eventObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/textbringer/controller.rb', line 116

def read_event
  if executing_keyboard_macro?
    return @executing_keyboard_macro.shift
  end
  event = read_event_nonblock
  if event
    return event
  end
  loop do
    if Window.echo_area.active?
      wait_files = [STDIN]
    else
      wait_files = [STDIN, @next_tick_input]
    end
    files, = IO.select(wait_files, nil, nil, 1)
    # KEY_RESIZE may be returned even if STDIN is not included in files.
    event = read_event_nonblock
    if event
      return event
    end
    if !Window.echo_area.active? && files&.include?(@next_tick_input)
      c = @next_tick_input.read_nonblock(1, exception: false)
      if !c.nil? && c != :wait_readable
        block = @next_tick_queue_mutex.synchronize {
          @next_tick_queue.shift
        }
        block.call
        Window.redisplay
      end
    end
  end
end