Class: Thaum::InputReader

Inherits:
Object
  • Object
show all
Defined in:
lib/thaum/input_reader.rb

Overview

Reads raw bytes from an input stream in a background thread and pushes KeyEvents onto a queue.

Constant Summary collapse

ESCAPE_TIMEOUT =

seconds to wait after a bare e before treating it as Escape

0.05

Instance Method Summary collapse

Constructor Details

#initialize(input:, queue:, parser: EscapeParser.new) ⇒ InputReader

Returns a new instance of InputReader.



8
9
10
11
12
13
# File 'lib/thaum/input_reader.rb', line 8

def initialize(input:, queue:, parser: EscapeParser.new)
  @input  = input
  @queue  = queue
  @parser = parser
  @thread = nil
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/thaum/input_reader.rb', line 24

def alive?
  @thread&.alive? || false
end

#startObject



15
16
17
# File 'lib/thaum/input_reader.rb', line 15

def start
  @thread = Thread.new { run }
end

#stopObject



19
20
21
22
# File 'lib/thaum/input_reader.rb', line 19

def stop
  @thread&.join(1)
  @thread = nil
end