class BBS::Petscii::CanvasMenu::Keys
The keys of the session; while waiting, the idle block every idle seconds.
Public Class Methods
Source
# File lib/bbs/petscii/canvas_menu.rb, line 95 def initialize(session, idle, on_idle) @session = session @idle = idle && on_idle ? idle : nil @on_idle = on_idle end
Reads the keys of session, calling on_idle every idle seconds without one (when both are given).
Public Instance Methods
Source
# File lib/bbs/petscii/canvas_menu.rb, line 103 def key loop do k = @session.readkey(timeout: @idle) raise IOError, 'the caller hung up' if k.nil? return k unless k == :idle && @idle out = @on_idle.call @session.write_raw(out) if out && !out.empty? end end
The next key; the bytes on_idle returns go out raw meanwhile. Raises IOError when the caller hangs up.