class BBS::Door
A door: a program the caller steps into from the BBS, as in the doors of the old boards. The BBS hands the telnet line over, the program talks to the caller directly, and the line comes back when the program exits.
The program is a BBS::FakeOS definition, a BBS::Flow, or anything that responds to call(session, context). A flow gets a copy of the caller’s context (so its ask steps cannot overwrite the BBS’s own keys), and since a flow ends without an exit command of its own, the door waits for ENTER before handing the line back:
SERMO = BBS::Door.new(:sermo, Sermo::OS, label: '&SERMO') SERMO.run(session, ctx)
Inside an Application, declare doors with the door DSL and let BBS::Application::Builder#run take the caller through them (see BBS::Application).
Attributes
A line about the door, shown on the statusbar while its menu entry is highlighted, or nil.
The door’s name as a Symbol, its menu label, and the program it runs.
The door’s name as a Symbol, its menu label, and the program it runs.
The door’s name as a Symbol, its menu label, and the program it runs.
Public Class Methods
# File lib/bbs/door.rb, line 38 def initialize(name, program, label: nil, hint: nil) raise ArgumentError, "Door #{name.inspect}: not a FakeOS definition or a callable" unless program.is_a?(FakeOS::Definition) || program.is_a?(Flow) || program.respond_to?(:call) @name = name.to_sym @program = program @label = label || name.to_s.upcase @hint = hint end
Creates a door.
- name
-
the door’s name, stored as a Symbol
- program
-
a
BBS::FakeOS::Definition, aBBS::Flow, or an object that responds tocall(session, context) - label
-
the text shown in menus; defaults to
namein capitals - hint
-
a line about the door for the statusbar, or
nil
Raises ArgumentError when program is none of the three.
Public Instance Methods
Source
# File lib/bbs/door.rb, line 58 def run(session, context = {}) session.disable_mouse session.write("#{Ansi::RESET}#{Ansi::CLEAR}") start(session, context) rescue IOError, SystemCallError raise rescue StandardError => e BBS.log("door #{@name}", "#{e.class}: #{e.message}\n#{e.backtrace&.first(3)&.join("\n")}") ensure (session.enable_mouse if BBS.config.mouse) rescue nil end
Hands the line to the program on a clean screen without mouse reporting, and takes it back when the program returns.
- session
-
the caller’s
BBS::Session - context
-
the caller’s context Hash; a
Flowprogram gets a copy
An error raised by the program is logged to stderr and swallowed, so the caller lands back on the board; IOError and SystemCallError (the line dropped) are re-raised. Mouse reporting is switched back on afterwards when BBS.config.mouse is set.