module BBS::Application::EventLoop
The event loop of an Application: read a key, make it a BBS::Event, hand it down the chain of receivers, tick while the caller is quiet, and end at the idle limit.
Constants
- RECEIVERS
-
The receivers an event goes to after the window switching keys, in order; the first that takes it ends the chain.
Public Instance Methods
Source
# File lib/bbs/application/event_loop.rb, line 40 def idle_limit @session.respond_to?(:idle_seconds) ? @session.idle_seconds : BBS.config.idle_seconds end
The idle limit in seconds for this run: the session’s idle_seconds when it has one, else BBS.config.idle_seconds; nil means no limit.
Source
# File lib/bbs/application/event_loop.rb, line 56 def line_lost? = @line_lost == true
True when the run ended because the line did (a hang-up, the idle limit): no door is opened after it.
Source
# File lib/bbs/application/event_loop.rb, line 26 def run @running = true start_idle event_turn while @running rescue IOError, Errno::EPIPE, Errno::ECONNRESET @line_lost = true nil ensure @session.write("#{Ansi::SHOW_CURSOR}#{Ansi::CLEAR}") @running = false end
Main event loop. Uses a short read timeout to fire periodic ticks for UI polling (chat, clock) while still detecting hard idle disconnects.
Draws the screen, reads a key with a one-second timeout and dispatches it as a BBS::Event: an open menubar first, then window switching keys, the top window, the menubar, the statusbar and the root container’s focused widget. A second without input calls tick!. After the idle limit without input (the session’s idle_seconds, set from BBS.config.idle_seconds) the on_idle callable runs; unless it returns :keep, the loop shows a message and ends. A handler’s StandardError is logged and the loop goes on. Ends when a handler returns :halt, stop! is called or the line drops (see line_lost?), then shows the cursor and clears the screen.
Source
# File lib/bbs/application/event_loop.rb, line 52 def stop! = (@running = false)
Makes the event loop end after the current event.
Source
# File lib/bbs/application/event_loop.rb, line 46 def tick! @on_tick&.call(self) @windows.each { |w| w.tick(self) } end
Periodic tick: notify on_tick callback and let each open window pull any asynchronous updates by overriding BBS::Window#tick.