Table of Contents

Saltbush Terminal: scripting

Saltbush Terminal runs Python and Lua scripts. A script is attached to the tab it starts from and drives that session: it sends text, waits for prompts, reads the screen, changes settings, opens tabs, transfers files and shows dialogs.

Python scripts run with the system python3; the saltbush module uses only the standard library and is supplied automatically. Lua 5.4 is built in, so no Lua installation is needed.

The interface is the same as Lantern Terminal's. Scripts written for Lantern (from lantern import app, require(“lantern”)) and scripts written for the SyncTERM-Lua fork run unchanged.

Python

from saltbush import app
 
tab = app.GetScriptTab()
tab.Screen.Send("printf '%s%s\\n' 'terminal-' 'ready'\r")
if not tab.Screen.WaitForString("terminal-ready", 5):
    raise TimeoutError("Endpoint did not respond")
print(tab.Caption, tab.Screen.Rows, tab.Screen.Columns)

Lua

local app = require("saltbush").app
local tab = app:GetScriptTab()
tab.Screen:Send("printf '%s%s\\n' 'terminal-' 'ready'\r")
assert(tab.Screen:WaitForString("terminal-ready", 5), "Endpoint did not respond")
print(tab.Caption, tab.Screen.Rows, tab.Screen.Columns)

Lua uses colon syntax for methods and dot syntax for properties. arg[0] is the script file and arg[1] the first argument; … holds the arguments too. Lua's standard libraries are available, and the script's folder is on package.path.

Build test prompts from pieces, as above, so a wait does not match its own echoed command line.

Interface

Application

Tabs

Screen

Sending marks the received stream first, so a reply that arrives at once is still there for the next wait. A successful wait uses up the text up to its match.

Session and configuration

BBS Directory

Low-level requests (Python _rpc(op, **values), Lua lantern.rpc(op, tab, values)), the same as Lantern Terminal's:

SyncTERM-Lua scripts

The first time a Lua script uses one of the SyncTERM-Lua globals (send, sendln, expect, expect_pattern, expect_regex, must_expect, waitfor, readline, quiet, sleep, idle, set_timeout, on, off, screen, screen_size, cursor, buffer, clear, raw, connected, disconnect, quit, now, message, input, confirm, log, regex, bbs, before, matched, script_path), the compatibility layer is loaded. Received text has escape sequences removed (unless raw(true)), expect uses up text up to its match, the default timeout is 30 seconds and the script stops when the connection closes. On a CP437 session the script sees the BBS's original CP437 bytes. bbs.password is always nil. log and print write to the Activity pane.

Safety

Scripts run with your user's permissions. Each run of the program has a private connection (a socket in a folder only you can open, plus a random token passed to the scripts it starts); other users cannot drive your sessions. Do not put passwords in scripts, and review recordings before sharing them. Input typed at password prompts is not recorded.