Scripting

Scripts can use Python or bundled Lua 5.4.9. Choose a .py or .lua file in Script → Run; logon scripts, saved script commands and –script also accept both. Use Script → Cancel to stop the current tab’s worker. Script errors appear in the Activity pane. A session that is still logging in counts as open, so a script can wait for a password, passphrase or host-key prompt and answer it with Send. The Lua scripting guide includes its syntax and API reference.

Python

Choose Script → Run and select a .py file. Python runs separately from the desktop UI. The application passes a private, per-instance local connection token and the originating tab ID; changing focus does not retarget the script. Cancellation terminates the script process and leaves the connection open.

Linux uses configured/system Python 3. Windows packages include a private Python runtime. Select a different interpreter under Global Settings → Automation if needed. The lantern module uses only the standard library.

from lantern 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)

Build test prompts from pieces so a wait does not match its own echoed command line. A screen send records the incoming-stream position before transmission, so an immediate reply is retained for the following wait.

Included interface

Get2 retains line separators; Get concatenates lines. Closed/locked sessions and invalid coordinates produce explicit errors. A session disconnected while waiting raises LanternError. Capture is bounded; truncation raises an error rather than silently dropping the beginning of a response.

The comprehensive SCRIPTING-API.md defines the larger API contract. Members outside the included interface above are not supplied by this release. Lua uses the same authenticated application API through its bundled worker; see LUA-SCRIPTING.md for language-specific details.

Back to Lantern Terminal