Class: TuiTui::EventStream
- Inherits:
-
Object
- Object
- TuiTui::EventStream
- Defined in:
- lib/tui_tui/event_stream.rb
Overview
Converts terminal input readiness and resize notifications into runtime events.
Instance Method Summary collapse
-
#initialize(input:, size:) ⇒ EventStream
constructor
A new instance of EventStream.
- #next_event(tick: 0.1) ⇒ Object
- #resized! ⇒ Object
Constructor Details
#initialize(input:, size:) ⇒ EventStream
Returns a new instance of EventStream.
9 10 11 12 13 14 15 |
# File 'lib/tui_tui/event_stream.rb', line 9 def initialize(input:, size:) @input = input @size = size @key_reader = KeyReader.new @resized = false @queue = [] end |
Instance Method Details
#next_event(tick: 0.1) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tui_tui/event_stream.rb', line 21 def next_event(tick: 0.1) return @queue.shift unless @queue.empty? if @resized @resized = false return ResizeEvent.new(size: @size.size) end ready = IO.select([@input], nil, nil, tick) return TickEvent.new unless ready raw = @key_reader.read_all(@input) return EofEvent.new if raw.nil? @queue.concat(raw.map { |event| event.is_a?(MouseEvent) ? event : KeyEvent.new(key: event) }) @queue.shift end |
#resized! ⇒ Object
17 18 19 |
# File 'lib/tui_tui/event_stream.rb', line 17 def resized! @resized = true end |