module BBS::Terminal
The first question of a call on a board with two faces: which one the terminal gets. The board guesses first from the telnet answers: a window wider than 40 columns is a modern terminal; 40 columns, or no answer at all (a C64 behind a WiFi modem talks plain TCP), most likely a Commodore. The question is plain ASCII in capitals, which an ANSI terminal and a C64 in either character set print alike, and each line names what goes on the wire: ANSI with xterm’s 256 colours and mouse, or PETSCII.
A key only picks, RETURN takes it: a line-mode telnet sends the digit and the RETURN together, and a RETURN left on the line would land in the first screen. A changed pick prints the prompt again on a new line, since the two machines go back a character differently. A caller who does not answer gets what is picked, or the guess.
Constants
- FACES
-
The two faces: for each, the digit shown, the label of its line in the question, and the keys that pick it.
- SETTLE
-
Seconds to wait for the telnet negotiation before guessing.
- WAIT
-
Seconds to wait for each key at the question before taking the pick.
Public Class Methods
# File lib/bbs/terminal.rb, line 49 def self.flow(title:, modern:, petscii:) faces = { modern: modern, petscii: petscii } Flow.define do call do |ctx, runner| face = Question.new(runner.session, title).ask next :halt if face.nil? Terminal.switch(runner.session, face) FlowRunner.new(runner.session, ctx[:session_id], faces[face], context: ctx).run nil end end end
The whole first step as a Flow: ask, switch the line (PETSCII on a C64, mouse reporting on a modern terminal when config.mouse is on), then run that face’s Flow. The board keeps config.mouse_on_connect off: the mouse’s escape sequence would be garbage on a C64.
- title
-
the board’s name, shown above the question
- modern
-
the
BBS::Flowfor a modern terminal - petscii
-
the
BBS::Flowfor a PETSCII line, a Commodore 64
Returns a BBS::Flow that halts when the line drops at the question.
BBS.configure { |c| c.flow = BBS::Terminal.flow(title: 'My board', modern: MODERN, petscii: PETSCII) }
Source
# File lib/bbs/terminal.rb, line 33 def self.guess(session) session.settle(timeout: SETTLE) && session.term_cols > Petscii::COLS ? :modern : :petscii end
Guesses the face of session from the telnet answers: :modern when the terminal reported its window size within SETTLE seconds and it is wider than 40 columns, :petscii otherwise.
Source
# File lib/bbs/terminal.rb, line 65 def self.switch(session, face) if face == :petscii session.petscii! elsif BBS.config.mouse session.enable_mouse end end
Switches the line of session to face: PETSCII on a C64, mouse reporting on a modern terminal when BBS.config.mouse is on.