Files
bbs/scripts.sample/oneliners.js
T
Claude 1805fcbd13 Add JavaScript scripting: the sysop's own screens, on every terminal
A script (scripts_dir/NAME.js, run by a menu's script:NAME, and logon.js
after each login) draws the BBS's shared screens through ui (menus,
tables, forms, panels, messages, the editor, confirmations), so one
script works on text, RIP and 3270 terminals.  It acts as its caller,
with their access: msg (areas, messages, posting, mail), node (who's
online, node messages, its activity), user, bbs; and keeps JSON values
in data, for everyone or (data.user) for the caller, in the database
(script_data).

goja runs it in strict mode, with no files, network or processes.  A
watchdog stops a script that computes more than two seconds between
screens (the caller's time at a screen is not counted); the caller
hanging up ends a script whatever it catches; failures are logged and
told (to a sysop, with why).  Scripts are compiled once, again when
changed; bbs check refuses scripts that do not compile and menus naming
missing ones.

goja is pinned to its June 2026 commit (the last that builds with Go
1.24; it is changing quickly now).

scripts.sample has one-liners and a poll; both are tested, the
one-liners on a text terminal and on a 3270 (s3270).  That test found
3270 forms broken since the shared screens: the input field began
under its label's last character, whose attribute byte erased it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-12 14:52:12 +00:00

34 lines
997 B
JavaScript

// One-liners: the last lines callers left, and one of yours.
//
// A menu item runs it: o = script:oneliners One-liners
// It works on every terminal: text, RIP and 3270.
var MOST = 15; // lines kept
function show() {
var lines = data.get("lines") || [];
var shown = lines.length ? lines.map(function (l) {
return {label: l.who + ":", text: l.text};
}) : ["No one has left a line yet."];
return ui.panel({
title: "One-liners",
lines: shown,
actions: [{id: "add", label: "Add a line", key: "a", pf: 5, short: "Add"}]
});
}
for (;;) {
node.doing("Reading one-liners");
if (show() !== "add") break;
var v = ui.form({
title: "Your one-liner",
fields: [{name: "text", label: "Your line", prompt: "Your line (Enter to give up): ", width: 60}],
submit: "Add"
});
if (!v || !v.text) continue;
var lines = data.get("lines") || [];
lines.push({who: user.name, text: v.text, when: new Date().toISOString()});
data.set("lines", lines.slice(-MOST));
ui.say("Added.", "good");
}