class BBS::FlowRunner
Runs a BBS::Flow on a session: each step in order (see BBS::Flow::Steps), writing to and reading from the caller’s line, with a context Hash that ask steps fill and later steps and blocks read.
BBS::FlowRunner.new(session, session_id, flow, context: { name: 'Zsolt' }).run
An error raised in a call block is reported to the caller and on stderr and the flow carries on; a dropped line (IOError, EPIPE, ECONNRESET) ends it.
Constants
- MENU_WIDTH
-
The width of a menu: it fits a C64’s 40 columns.
- STOPS
-
The results of a step that end the steps being run.
- STYLES
-
The colour of each
styleof a step, from the one ANSI palette (BBS::Ansi). An unknown style is:muted.
Attributes
The caller’s session ID, the BBS::Session the flow runs on, and the context Hash the steps share.
The caller’s session ID, the BBS::Session the flow runs on, and the context Hash the steps share.
The caller’s session ID, the BBS::Session the flow runs on, and the context Hash the steps share.
Public Class Methods
# File lib/bbs/flow_runner.rb, line 35 def initialize(session, session_id, flow, context: {}) @session = session @session_id = session_id @flow = flow @context = { **context, session_id: session_id } end
Creates a runner for flow (a BBS::Flow) on session. context seeds the flow’s context, such as the caller’s name when a flow runs as a door; session_id is stored in it under :session_id.
Public Instance Methods
Source
# File lib/bbs/flow_runner.rb, line 70 def ask(prompt) return Field.ask(@session, prompt, max: Telnet::MAX_LINE).to_s.strip if petscii? write prompt readline&.strip rescue IOError nil end
Writes prompt and reads the answer, stripped: in a BBS::Field on a PETSCII line, which edits with the cursor keys, a plain line otherwise. Returns nil when the caller hangs up.
Source
# File lib/bbs/flow_runner.rb, line 94 def color(style) = STYLES.fetch(style, STYLES[:muted])
The SGR sequence of style (a STYLES key; an unknown one is :muted).
Source
# File lib/bbs/flow_runner.rb, line 50 def execute(steps) steps.each do |step| result = step.run(self) return result if STOPS.include?(result) end nil end
Runs steps in order until one returns a STOPS result, which is returned; nil when they all ran.
Source
# File lib/bbs/flow_runner.rb, line 90 def line(text, style: :muted) = write(" #{color(style)}#{text}#{Ansi::RESET}#{Ansi::CRLF}")
Writes text as one line indented by two spaces, in the colour of style.
Source
# File lib/bbs/flow_runner.rb, line 65 def readline(mask: nil) = @session.readline(mask: mask)
Reads a line from the caller, echoing mask in place of each character when given. Returns the line, or nil when the caller hung up.
Source
# File lib/bbs/flow_runner.rb, line 46 def run = execute(@flow.steps)
Runs the flow’s steps until they end or one stops the flow. Returns :halt when the flow was stopped (a hang-up, a failed ask or gate, a refused confirmation, a block returning :halt), :exit_menu when an exit_menu step ran outside a menu, nil otherwise.
Source
# File lib/bbs/flow_runner.rb, line 98 def screens_dir = @flow.screens_dir || BBS.config.screens_dir
The folder of the flow’s ERB screens: its own, or BBS.config.screens_dir.
Source
# File lib/bbs/flow_runner.rb, line 82 def select(options, hint: nil) write Ansi::CRLF items = options.map { |label, value| Selector.item(label, value: value) } Selector.new(@session, items, width: MENU_WIDTH, numbers: true, hint: hint).run end
A numbered BBS::Selector of options, pairs of label and value, with hint on its status row. Returns the value taken, or nil for RUN/STOP, ← or Esc.
Source
# File lib/bbs/flow_runner.rb, line 60 def write(data) = @session.write(data)
Writes data to the caller’s line. Blocks of call steps get the runner as their second argument to write with.