class
Termisu::Event::Source::Input
- Termisu::Event::Source::Input
- Termisu::Event::Source
- Reference
- Object
Overview
Terminal input event source.
Wraps Reader and Input::Parser to produce Key and Mouse events
via a dedicated polling fiber.
Usage
reader = Termisu::Reader.new(terminal.infd)
parser = Termisu::Input::Parser.new(reader)
input = Termisu::Event::Source::Input.new(reader, parser)
loop = Termisu::Event::Loop.new
loop.add_source(input)
loop.start
while event = loop.output.receive?
case event
when Termisu::Event::Key
break if event.key.escape?
when Termisu::Event::Mouse
puts "Click at #{event.x},#{event.y}"
end
end
Thread Safety
Uses Atomic(Bool) for the running state. Safe to call #start/#stop
from different fibers.
Defined in:
termisu/event/source/input.crConstant Summary
-
Log =
Termisu::Logs::Event -
POLL_INTERVAL_MS =
10 -
Polling interval for input checking. 10ms provides responsive input without excessive CPU usage.
Constructors
-
.new(reader : Termisu::Reader, parser : Termisu::Input::Parser)
Creates a new input source.
Instance Method Summary
-
#name : String
Returns the source name for identification.
-
#running? : Bool
Returns true if the input source is currently running.
-
#start(output : Channel(Event::Any)) : Nil
Starts polling for input events and sending them to the output channel.
-
#stop : Nil
Stops polling for input events.
Instance methods inherited from class Termisu::Event::Source
name : String
name,
running? : Bool
running?,
start(output : Channel(Event::Any)) : Nil
start,
stop : Nil
stop
Constructor Detail
Creates a new input source.
reader- Reader instance for raw inputparser- Parser instance for escape sequence parsing
Instance Method Detail
Starts polling for input events and sending them to the output channel.
Spawns a fiber that polls for input at POLL_INTERVAL_MS intervals
and sends parsed events to the channel.
Prevents double-start with compare_and_set.
Stops polling for input events.
Sets the running flag to false, causing the fiber to exit on its next iteration. Uses compare_and_set for idempotent stop operations.