class BBS::Application
The widget event loop. Acts as the root container:
root_panel — base UI (drawn behind windows) menubar — optional, Alt-letter pulldown menus statusbar — optional, hotkey hints at the bottom window stack — modal windows on top of root_panel
Build one with Application.define { … } DSL, or instantiate directly and use add_window / menubar / statusbar.
Doors (BBS::Door) are declared in the DSL and opened from any handler; Builder#run then hands the line to the door and rebuilds the application when the caller comes back:
APP = BBS::Application.define do door :sermo, Sermo::OS, label: '&SERMO' menubar do menu('&Doors') { doors } # one item per declared door end end APP.run(session: session, session_id: sid, context: ctx)
Constants
- BACKTRACE_LINES
-
Lines of the backtrace logged with a handler’s error.
- BAR_HEIGHT
-
Rows the menubar and the statusbar each take.
- IDLE_MESSAGE_WAIT
-
Seconds the idle disconnect message stays before the line is dropped.
- LOADING_CHROME
-
Columns the “Please wait” box of
with_loadingtakes beside its text. - MIN_DESKTOP_ROWS
-
The fewest rows the desktop between the bars is given.
- TICK_SECONDS
-
Seconds between two
tick!calls while no key comes. - UNNUMBERED
-
The sort key of a window without a number: after every numbered one.
- WINDOW_NUMBERS
-
The window numbers handed out, shown in the frame and picked with Alt-1 … Alt-9.
Attributes
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
- session
-
the
BBS::Sessionthe application draws on and reads from session_id-
the session’s id
- context
-
the caller’s context Hash, shared with the flow and doors
- root
-
the root
BBS::Containerbehind all windows - menubar
-
the
BBS::Menubar, ornil - statusbar
-
the
BBS::Statusbar, ornil - windows
-
the open windows, bottom to top (the last is in front)
- theme
-
the
BBS::Themeevery widget is drawn with - services
-
Hash of service objects handed to window callbacks
window_specs-
Hash of the registered
BBS::WindowSpecobjects by name - doors
-
Hash of the declared
BBS::Doorobjects by name
Public Class Methods
Source
# File lib/bbs/application.rb, line 83 def self.define(&block) builder = Builder.new builder.instance_eval(&block) if block builder end
Evaluates the DSL block in a new Builder and returns the Builder; call Builder#run (or Builder#build) on it for each session.
# File lib/bbs/application.rb, line 105 def initialize(session:, session_id:, context: {}, theme: nil, on_idle: nil, on_tick: nil, helpers: nil, services: {}, window_specs: {}, doors: {}) @session = session @session_id = session_id @context = context @theme = theme || BBS.config.theme || Theme.synchronet @root = Container.new.tap { |root| root.theme = @theme } @windows = [] @on_idle = on_idle @on_tick = on_tick @services = services @window_specs = window_specs @doors = doors extend(helpers) if helpers end
Creates an application with no windows, menubar or statusbar.
- session
-
the
BBS::Sessionto run on session_id-
the session’s id
- context
-
the caller’s context Hash
- theme
-
the
BBS::Theme; defaultBBS.config.theme, orBBS::Theme.synchronetwhen that is not set either - on_idle
-
callable invoked as
call(app)when the caller reaches the idle limit (seerun); returning:keepkeeps the caller on and starts the count again - on_tick
-
callable invoked as
call(app)on every tick (seetick!) - helpers
-
a Module the application is extended with
- services
-
Hash of service objects for window callbacks
window_specs-
Hash of
BBS::WindowSpecobjects by name, foropen_window - doors
Public Instance Methods
Source
# File lib/bbs/application.rb, line 142 def add(child) @root.add(child) child.theme = @theme child end
Adds the widget child to the root container, behind all windows, and gives it the application’s theme. Returns child.
Source
# File lib/bbs/application.rb, line 122 def cols = @session.term_cols || Telnet::DEFAULT_COLS
The terminal width in columns (80 when the session does not know it).
Source
# File lib/bbs/application.rb, line 153 def open_door(name) door = @doors[name.to_sym] raise ArgumentError, "Unknown door: #{name.inspect}" unless door @context[:door] = door stop! :halt end
Leaves the application through a declared door, from any handler: a menu item, a key, a window button or a list’s Enter. The event loop stops after this event, and Builder#run opens the door. Stores the door under context[:door]. Returns :halt, so a handler can also end with it. Raises ArgumentError for an unknown door name.
Source
# File lib/bbs/application.rb, line 124 def rows = @session.term_rows || Telnet::DEFAULT_ROWS
The terminal height in rows (24 when the session does not know it).
Source
# File lib/bbs/application.rb, line 135 def statusbar=(statusbar) @statusbar = statusbar statusbar.theme = @theme if statusbar end
Sets the BBS::Statusbar shown on the bottom row (or nil for none) and gives it the application’s theme.
# File lib/bbs/application.rb, line 165 def with_line @session.disable_mouse @session.write("#{Ansi::RESET}#{Ansi::CLEAR}") yield @session ensure @session.enable_mouse if BBS.config.mouse @committed = nil end
Hands the raw line to the block, a file transfer for one, on a clean screen without mouse reporting, and repaints the whole application when it returns. Returns what the block returns.
# File lib/bbs/application.rb, line 176 def with_loading(text = 'Working...', &block) win = Dialogs.message(self, text, title: ' Please wait ', width: text.length + LOADING_CHROME) render_screen Thread.new do @loading_result = block.call ensure close_window(win) end.join @loading_result end
Shows a “Please wait” message with text, runs the block in a thread and waits for it, then closes the message. Returns the block’s value.