Modules
A module is one BBS feature (oneliners, the message reader, the user editor), written as a class with a handle() method. Menus run modules; modules talk to the caller through Terminal. This page covers writing a module, then lists the Terminal API and the widgets.

- Write a module
- What handle() receives
- Return values
- Module helpers
- Session essentials
- Terminal reference
- Keys
- Widgets
- Colours
Write a module
-
Generate the class:
php carrier make:module RumorsCreated app/Modules/Rumors.php Add it to a menu in app/Menus.php: $menu->option('X', 'Rumors')->module(Modules\Rumors::class); -
Fill in
handle(). The generated file already extendsCarrier\Menu\Moduleand has a workinghandle(). This version reads a random line fromresources/rumors.txt:<?php declare(strict_types=1); namespace App\Modules; use Carrier\Config\BbsConfig; use Carrier\Menu\Module; use Carrier\Menu\Next; use Carrier\Session\Session; use Carrier\Terminal\PipeCodes; use Carrier\Terminal\Terminal; final class Rumors extends Module { protected string $activity = 'Reading rumors'; public function __construct(private readonly BbsConfig $config) { } public function handle(Session $session, Terminal $terminal): ?Next { $this->header($terminal, $session, 'Rumors', art: 'rumors'); $lines = @file($this->config->resources('rumors.txt'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: ['No rumors yet.']; $terminal->writeln('|07' . PipeCodes::escape($lines[array_rand($lines)])); $terminal->pause(); return null; } } -
Add it to a menu in app/Menus.php:
$menu->option('R', 'Rumors')->module(Modules\Rumors::class); -
Run
php carrier menu:listto confirm the class resolves. See menus.
Modules are resolved from the container on every run, so constructor injection works. $activity is what Who's Online shows while the module runs. An option's ->activity('…') overrides it.
What handle() receives
Module does not fix the signature of handle(). The ModuleRunner calls it through the container with these named values:
| Parameter name | Value |
|---|---|
$session |
the caller's Carrier\Session\Session |
$terminal |
$session->terminal |
$args |
the whole argument array from the menu |
| any key of that array | its value, by name |
Every other parameter is injected by type from the container. Menu arguments arrive by name:
// app/Menus.php
$menu->option('Y', 'Page the sysop')->module(Modules\PageNode::class, ['sysop' => true]);
// app/Modules/PageNode.php
public function handle(Session $session, Terminal $terminal, ModuleRunner $modules, bool $sysop = false): voidTo run one module from another, inject Carrier\Menu\ModuleRunner and call run(string $module, Session $session, array $args = [], ?string $activity = null): ?Next:
$this->modules->run(MessagePost::class, $session, ['areaId' => $area->key()]);Return values
handle() returns |
The menu runner |
|---|---|
nothing, null or anything that is not a Next |
redraws the current menu |
Next::stay() |
redraws the current menu |
Next::prompt() |
shows only the prompt again |
Next::menu('name') |
goes to that menu |
Next::reset('name') |
clears the menu history, then goes to that menu |
Next::back() |
goes back one menu |
Next::logoff() |
logs off without asking |
For the history rules, see menus.
Module helpers
Protected methods on Module.php:
| Method | Does |
|---|---|
header(Terminal $terminal, Session $session, string $title, ?string $art = null): ?Screen |
draws $art if the theme has it and returns its Screen. Otherwise clears the screen, draws the theme's header line with $title, and returns null. |
art(Session $session, string $name, array $options = []): ?Screen |
draws named art; null when the theme has none |
art() options, from ArtPresenter.php:
| Option | Meaning | Default |
|---|---|---|
cls |
clear the screen first | true |
pause |
false, true/'end' (pause after), or 'page' (pause every screenful) |
false |
baud |
emulate a line speed while drawing | the caller's setting |
mci |
extra one-off display codes, ['XX' => 'value'] |
[] |
row |
start drawing at this screen row, without clearing | — |
A returned Screen gives access to the art's views ($screen->view('ET1'), $screen->ofType('ET')), so a module can put input fields where the artist drew them. See art.
Session essentials
Session.php members a module typically uses:
| Member | |
|---|---|
$session->user |
?Carrier\Auth\User; null before login |
user(): User |
the logged-in user; throws LogicException when nobody is logged in |
isLoggedIn(): bool |
|
handle(): string |
the user's handle, or 'Guest' |
can(?string $acs): bool |
evaluate an ACS string; null and '' allow |
isSysop(): bool |
security level at or above BbsConfig::$sysopLevel |
level(): SecurityLevel |
the caller's level name and daily minutes |
minutesLeft(): ?int |
minutes left today; null for unlimited or not logged in |
theme(): Theme |
the caller's theme (themes) |
$session->config |
the BbsConfig |
$session->data |
per-call scratch array (current message area, lightbar positions …) |
$session->node |
node number |
$session->nodes |
the NodeManager: other sessions, broadcasts |
notify(NodeMessage $message): void |
deliver a node message to this caller |
disconnect(string $reason = 'Disconnected'): void |
hang up |
Terminal reference
Carrier\Terminal\Terminal, in Terminal.php. Methods without a listed return type return $this, so calls chain.
Output
| Method | Does |
|---|---|
write(string $text) |
write text with pipe codes and display codes |
writeln(string $text = '') |
write() plus CRLF |
text(string $text) |
write literally: no pipe or display codes, ESC removed |
raw(string $text) |
write UTF-8 that may hold escape sequences; no pipe processing; still converted to CP437 when needed |
bytes(string $bytes) |
write bytes as given, with no charset conversion |
cls() |
reset colours and clear the screen |
gotoXY(int $col, int $row) |
move the cursor (1-based) |
clearEol() |
clear to the end of the line |
color(int $fg, ?int $bg = null) |
set colours by pipe-code number (0–15, background 0–15) |
reset() |
reset colours |
hideCursor() / showCursor() |
|
bell() |
BEL |
center(string $text, ?int $width = null) |
write a line centred in $width (default: terminal width, at most 80) |
colors(): ColorMode |
how colours are sent to this terminal (below) |
encode(string $text): string |
$text as it would go out (CP437 on a CP437 terminal) |
Text is UTF-8 everywhere inside the BBS. To show a string the caller typed inside pipe-coded text, escape it with PipeCodes::escape(). Without escaping, a handle like |12Bob would change colours. For pipe codes, display codes and the |PA/|CL control codes, see art.
PipeCodes (in PipeCodes.php) helpers:
| Static method | Returns |
|---|---|
escape(string $text): string |
$text safe to embed: | doubled, ESC removed |
strip(string $text): string |
$text without pipe colour and control codes (display codes stay) |
length(string $text): int |
printable width of pipe-coded text |
pad(string $value, string $mode, int $width): string |
pad or cut to $width; $mode 'R' pads on the right, 'L' on the left, anything else centres |
Input
| Method | Returns |
|---|---|
readKey(?float $timeout = null, ?Cancellation $cancellation = null): ?Key |
the next key; null when $timeout seconds pass |
hasKey(): bool |
whether a key is waiting, without blocking (for game loops) |
flushInput(): void |
discard typed-ahead keys |
readLine(int $max = 60, ?string $mask = null, string $default = '', ?string $allow = null, bool $upper = false, bool $escapable = false, ?int $field = null, ?string $fieldColor = '|15|17'): ?string |
a line of input; null on Escape when $escapable |
ask(string $prompt, int $max = 60, string $default = '', ?string $allow = null, bool $escapable = false): ?string |
write $prompt, then readLine() |
password(string $prompt, int $max = 40): string |
readLine() echoing $passwordChar |
confirm(string $question, bool $default = true): bool |
a Y/N answer; Enter takes $default |
hotkey(string $keys, bool $escapable = false, ?Cancellation $cancellation = null): ?string |
one of $keys, upper-cased; "\r" for Enter when $keys contains "\r"; null on Escape when $escapable |
pause(?string $prompt = null): void |
show the pause prompt and wait for a key |
readLine() editing: Backspace, Delete and Left erase a character; Ctrl-U and Ctrl-X clear the line; Ctrl-W deletes a word. $allow is a regex character class such as 'A-Za-z0-9_'. $field draws an input box $field characters wide in $fieldColor.
readKey() throws Carrier\Terminal\Disconnected when the caller hangs up or the idle timeout passes. It throws Amp's CancelledException when $cancellation fires. Pass $session->interruption() to give up the wait when a node message arrives, as the menu runner does. Let Disconnected propagate; the node manager handles it.
Properties
| Property | Type | Meaning |
|---|---|---|
info |
TerminalInfo |
type, cols, rows, encoding, ansi, cterm, colorMode |
attr |
Attr |
the current colour attribute |
baud |
int |
emulated line speed; 0 = full speed |
idleTimeout |
int |
seconds before an idle caller is dropped; 0 disables |
passwordChar |
string |
'*' (themes override it) |
pausePrompt |
string |
'|08[ |07Press any key |08]' (themes override it) |
connection |
Connection |
the transport |
probe(float $timeout = 1.5): void re-runs terminal detection. Settings calls it when the caller switches the character set back to "Detect".
Keys
readKey() returns a Carrier\Terminal\Key, defined in Key.php:
| Member | |
|---|---|
$key->code |
a KeyCode |
$key->char |
the character for KeyCode::Char, the letter for KeyCode::Ctrl |
is(KeyCode ...$codes): bool |
whether the key is any of these |
isChar(?string $char = null): bool |
a printable character, or that character (case-insensitive) |
isCtrl(string $letter): bool |
Ctrl plus that letter |
upper(): string |
the character upper-cased, '' for other keys |
KeyCode cases: Char, Ctrl, Enter, Backspace, Delete, Tab, BackTab, Escape, Up, Down, Left, Right, Home, End, PageUp, PageDown, Insert, F1–F12.
$key = $terminal->readKey();
if ($key->is(KeyCode::Escape) || $key->isChar('Q')) {
return;
}Widgets
All widgets are in Carrier\Terminal\Widgets. Colour arguments are pipe codes ('|15|17' = white on blue).
Lightbar
A highlight over items placed anywhere on screen: a vertical list, a horizontal bar or a grid. Arrows move to the nearest item in that direction. Source: Lightbar.php.
new Lightbar(Terminal $terminal, array $items, string $normal = '|07|16', string $focus = '|00|23', int $selected = 0)
run(?Cancellation $cancellation = null, array $passKeys = []): int|Key|null| Key | Effect |
|---|---|
| arrows, Tab | move |
| Home / PageUp, End / PageDown | first / last item |
| an item's hotkey | picks it at once |
| Enter | picks the focused item |
| Escape | returns null |
a key in $passKeys (KeyCode or character) |
returned as a Key |
$items is a list of LightbarItem:
new LightbarItem(int $col, int $row, int $width, string $label, ?string $key = null, ?string $normal = null, ?string $focus = null)Picker
A scrolling list of pipe-coded rows: message lists, user lists. Source: Picker.php.
new Picker(Terminal $terminal, array $rows, int $top, int $height, int $col = 1, ?int $width = null, string $focus = '|15|17', int $selected = 0)
run(array $passKeys = []): int|Key|null
update(int $index, string $row): void
draw(): void| Key | Effect |
|---|---|
Up / K, Down / J |
move |
| PageUp, PageDown / Space | move a page |
| Home, End | first, last |
| Enter | returns the row index |
Escape / Q |
returns null |
a key in $passKeys |
returned as a Key |
From Settings.php:
$picker = new Picker($terminal, $rows, 4, count($rows), width: 60, selected: $selected);
$picked = $picker->run();
if (! is_int($picked)) {
return;
}Pager
"More?" paging for long output. Source: Pager.php.
Pager::show(Terminal $terminal, iterable $lines, int $usedRows = 0, bool $pauseAtEnd = true): bool
Pager::wrap(string $text, int $width = 79): arrayshow() writes pipe-coded lines and stops every screenful at [More? Y/n/c]. C continues without stopping; N or Q stops and returns false. $usedRows counts lines already on screen. wrap() word-wraps text into lines and keeps blank lines.
Editor
The full-screen message editor, with word wrap and quoting. On a terminal without ANSI it falls back to a line editor, where /s saves and /a aborts. Source: Editor.php.
new Editor(Terminal $terminal, string $initial = '', array $quote = [], int $top = 4, ?int $bottom = null, int $maxLines = 500, string $color = '|07', string $quoteColor = '|03')
run(): ?string| Key | Effect |
|---|---|
| arrows, Home/End, PgUp/PgDn | move |
| Enter | split the line |
| Backspace / Delete | join lines at the edges |
| Ctrl-Z or Ctrl-S | save |
| Esc | command line: (S)ave (A)bort (Q)uote (C)ontinue |
run() returns the text, or null when the caller aborts. $quote is the list of lines offered by (Q)uote. $bottom defaults to the last row but one. The message poster calls it like this:
$body = (new Editor($terminal, quote: $quote, top: 5))->run();Colours
Pipe codes name the sixteen DOS colours. How they reach the caller depends on $terminal->colors(), a Carrier\Terminal\ColorMode (ColorMode.php):
| Mode | Sent as | Chosen for |
|---|---|---|
TrueColor |
exact VGA RGB (38;2;r;g;b) |
terminal types naming ghostty, kitty, wezterm, alacritty, foot, iterm, contour, rio, direct, truecolor or 24bit; or SSH COLORTERM=truecolor/24bit |
Xterm256 |
nearest fixed 256-colour entry | terminal types containing 256col |
Aixterm |
30–37/90–97, 40–47/100–107 in the terminal's own palette |
everything else, and the web terminal |
CTerm |
bold for bright text, blink for bright backgrounds (with ESC[?33h) |
SyncTERM and other CTerm clients |
Bold |
bold for bright text, no bright backgrounds | terminals without iCE colours |
Callers can override the guess under Settings → Colours, which cycles through Auto, Terminal theme, VGA 256-colour and VGA 24-bit. Modules don't need to care: write(), color() and art drawing all go through the same mode. Pass $terminal->colors() when building SGR yourself with Attr::sgr().